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返回一個新對象,其中所有先前設置的變量都恢復爲默認值。

回答