# Join

**URL:** <https://www.ruby-forum.com/t/join/95111>\
**Category:** Rails\
**Created:** [January 13, 2006, 1:54am UTC](https://www.ruby-forum.com/t/join/95111 "2006-01-13T01:54:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [January 13, 2006, 1:54am UTC](https://www.ruby-forum.com/t/join/95111/1 "2006-01-13T01:54:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [January 13, 2006, 3:00am UTC](https://www.ruby-forum.com/t/join/95111/2 "2006-01-13T03:00:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [January 13, 2006, 11:03am UTC](https://www.ruby-forum.com/t/join/95111/3 "2006-01-13T11:03:23Z")

</div>

> > ```
> > :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.,
