假设有模型customer,account并且address:
class Customer
has_many :accounts
end
class Account
belongs_to :customer
has_many :addresses
end
class Address
belongs_to :account
end
给定一个对象地址,它的客户可以被检索为:
customer = address.account.customer
现在让我们将关系存储在字符串变量address_relation = 'account.customer'中。给定一个address对象,有没有办法customer用字符串变量检索它,address_relation例如:
customer = address.address_relation?
谢谢您的帮助。