undefined method `[]' for :stocktbl:Symbol

Hi,

I have a user class as so:

class Artisttbl < ActiveRecord::Base set_primary_key “artist_id” has_one :artistbiogtbl, :foreign_key => “artist_id”, :dependent => :delete has_many :artistimagestbl, :foreign_key => “artist_id”, :dependent => :delete_all

has_many :trackcounttbl, :foreign_key => “artist_id”, :dependent => :delete_all has_many :stocktbl, :foreign_key => “artist_id”, :dependent => :delete_all

def self.getFeaturedArtist

  Artisttbl.find(:first, :include => [:artistbiogtbl, :artistimagestbl, :stocktbl[:conditions => ['stock_id = ?', :stock_id]]], :conditions => {:featured => 'true'})
end

end

I am getting the above mentioned error message whn trying to perform getFeaturedArtist. What I am trying to do is:

  1. Find a ‘featured’ artist record and to ‘include’ an associated artistbiogtbl record, artistimagtbl record and stocktbl record. But on the stocktbl I wish a condition to be set which is simply that the Stocktbl.stock_id must be equal to the Artisttbl.stock_id.

What is the best way to do this?

Andrew Madu wrote:

      Artisttbl.find(:first, :include => [:artistbiogtbl, :artistimagestbl, :stocktbl[:conditions => ['stock_id = ?', :stock_id]]], :conditions => {:featured => 'true'})

That include with conditions syntax is not valid.

Have a read through this thread: http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/5199cea1d6267c5c

Hi Mark, that did the trick! Many thanks.