1
是否有方法从关联方法内访问proxy_association对象?从关联方法内访问Rails proxy_association.owner
例子:
class User < ActiveRecord:Base
has_many :accounts
end
class Account < ActiveRecord:Base
belongs_to :user
def some_function
# Here I want to access the same user object the association was called on
# (that holds all already defined global variables), not a newly created object
# through self.user (where all global variables are reset).
proxy_association.owner
end
end
如何访问一个协会是由该协会中呼吁的对象?不幸的是,self.user
返回一个新对象,其中所有先前设置的变量都恢复为默认值。
没办法......不要问我,因为我是多久试图左右...... – jones
哈哈,我已经有太多。很高兴我能帮上忙。 – Shane