【发布时间】:2012-03-09 20:37:57
【问题描述】:
我有几个模型是多个对象的组合。我基本上手动管理它们以进行保存和更新。但是,当我选择项目时,我无权访问所述项目的相关属性。例如:
class ObjectConnection < ActiveRecord::Base
def self.get_three_by_location_id location_id
l=ObjectConnection.find_all_by_location_id(location_id).first(3)
r=[]
l.each_with_index do |value, key|
value[:engine_item]=Item.find(value.engine_id)
value[:chassis_item]=Item.find(value.chassis_id)
r << value
end
return r
end
end
以及每个项目:
class Item < ActiveRecord::Base
has_many :assets, :as => :assetable, :dependent => :destroy
当我使用 ObjectLocation.find_three_by_location_id 时,我无权访问资产,而如果在大多数其他情况下使用 Item.find(id),我可以。
我尝试使用包含,但似乎没有这样做。
谢谢
【问题讨论】:
标签: ruby-on-rails activerecord ruby-on-rails-3.1