Join


#1

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 A.


#2

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 A.

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


#3
:limit => 10)
  • FROM

objects
Hi, Thanks for you feedback.

I am not sure if that will join both entities. But assuming it will, I
have two doubts about how to use find:

  • if I don’t want the join;

  • for a :condition like user.valid = true and expires_date >= now()

Paulo A.,