不完全确定如何正确表达我的需要。代码更好地反映了它:
class Product < ActiveRecord::Base
def self.know_your_parent
p ? # <------- is it possible to get order.id here?
end
end
class Order < ActiveRecord::Base
has_many :products
end
(order=Account.new).assign_attributes({id: 4}, without_protection: true)
order.products.know_your_parent # => "4"