Sounds like you're looking for the 'conditions' option on belongs_to. Something like:
belongs_to :location, :class_name => "Asset", :conditions => "asset_category_type_id = 1" The other possibility would be to use the options attribute on the associated select-one: <select-one:location options="&Asset.find_by_asset_category_type_id(1)"/> Bryan On Wed, Jun 15, 2011 at 9:09 AM, Raklet <[email protected]> wrote: > 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. > > -- 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.
