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