Hey all
I have:
Item has_many :refs
Ref belongs_to :item
Item has_many :sales
Sale belongs_to :item
I would like to find all refs that have been sold 2 days ago and which
name=‘gizmo’
I tried that:
@refs= Ref.find(:all,:include=>[‘item’,‘sale’]
:conditions=>[refs.name=? and
items.sales.created_on=?’,’%gizmo%,2.days.ago’])
but item.sales.created_on. any idea how to make the query right?
thanx in advance
Pat
Patrick A. wrote:
:conditions=>[refs.name=? and
items.sales.created_on=?‘,’%gizmo%,2.days.ago’])
but item.sales.created_on. any idea how to make the query right?
Have a read of the Table Aliasing Section of the
ActiveRecord::Associations
API: http://pages.citebite.com/r1s2x4d5s2mgd
Look at SQL the shown in the development log or error page to help you
find the right table name to use.
–
We develop, watch us RoR, in numbers too big to ignore.