[Rails] Re: JOIN

Kevin Olbrich
2006-01-13T02:00:19Z

unknown wrote:
> Hi!
>
> For the following example I want to retrieve the last 10 LastEntries for
> experis_date >= now.
>
> class User < ActiveRecord::Base
>   has_one :last_entries
>   def self.last_entry_items
>     find(:all,
> #    :include => "last_entries",
> #    :conditions => "last_entries.expires_date >= now()",
>     :order => "id desc",
>     :limit => 10)
>   end
> end
>
> class LastEntrie < ActiveRecord::Base
> 	belongs_to :user
> end
>
> Rails tells me the following:
>
> Mysql::Error: #42S02Unknown table ''last_entries'' in where
clause: SELECT
> * FROM
> users WHERE (last_entries.expires_date >= now())  ORDER BY id desc
> LIMIT 10
>
> I was expecting to see here an inner join or something. Then I tried
> using
> :include and rails gave the following error:
>
> uninitialized constant LastEntries
>
> I would apreciate any tip on this subject.
>
> Thanks for you attention,
>
> Paulo Abreu

Try

LastEntrie.find(:all, :condition=>"expires_date >= now()",
:order=>"id
desc", :limit=>10)

This will return LastEntrie objects. Your call would try to return User
objects

--
Posted via http://www.ruby-forum.com/.