I have three models. I have provided their relevant attributes and
associations for this discussion:
asset_category_type
fields do
name :string
end
has_many :asset_categories
asset_category
fields do
name :string #example values: location, equipment, part
end
belongs_to :asset_category_type
asset
fields do
name :string #example values: shop (is a location), tractor
(is an equipment), wrench (is a tool)
end
belongs_to :asset_category # this generates a drop down just
fine. Asset should have a category defined
has_many :children, :class_name => "Asset", :foreign_key =>
"parent_id"
belongs_to :parent, :class_name => "Asset" #this is ok too.
Asset can belong to another asset.
has_many :locations, :class_name => "Asset", :foreign_key =>
"location_id"
belongs_to :location, :class_name => "Asset" #this is the trouble
spot. Asset should have a location (another asset) defined, but I
only want to display assets that are of asset_category_type =
'location'
This is the code I can use in rails console to obtain a list of assets
that are of asset_category_type = 'location'
Asset.joins(:asset_category
=> :asset_category_type).where('asset_categories.asset_category_type_id'
=> 1)
but how do I translate that into the belongs_to so that hobo only
displays the selected assets?
--
You received this message because you are subscribed to the Google Groups "Hobo
Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/hobousers?hl=en.