# ActiveRecord crashes on :include and :limit. is there a fix

**URL:** <https://www.ruby-forum.com/t/activerecord-crashes-on-include-and-limit-is-there-a-fix/112731>\
**Category:** Rails\
**Created:** [August 22, 2007, 5:26pm UTC](https://www.ruby-forum.com/t/activerecord-crashes-on-include-and-limit-is-there-a-fix/112731 "2007-08-22T17:26:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Phlip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ed8c4c/32.png) [@Phlip](https://www.ruby-forum.com/u/Phlip)\
**Post date:** [August 22, 2007, 5:26pm UTC](https://www.ruby-forum.com/t/activerecord-crashes-on-include-and-limit-is-there-a-fix/112731/1 "2007-08-22T17:26:42Z")

</div>

Railsters:

Our design is just one refactor away from attaining Nirvana (and  
deleting a _lot_ of code!). Only this bug stands between us and  
enlightenment:

[http://dev.rubyonrails.org/ticket/6415](http://dev.rubyonrails.org/ticket/6415)

Here’s a synopsis:

```
Frog.find( :all, :include => { :species => ['clade'] },
                  :conditions => ['clade_id in (?)', 1],
                  :limit => 12 )

```

That produces this:

ActiveRecord::StatementInvalid: Mysql::Error: Unknown column  
‘clade\_id’ in ‘where clause’: SELECT id FROM frogs WHERE (clade\_id in  
(1)) LIMIT 12

That SELECT is clearly missing most of its details, including niceties  
like frogs.\* for the result columns.

Without the :limit, it works fine (so I don’t think that :offset is  
implicated, like the ticket says).

I’m going into ActiveRecord to monkey patch this. Has anyone tried yet?

–  
Phlip  
[http://www.oreilly.com/catalog/9780596510657/](http://www.oreilly.com/catalog/9780596510657/)  
^ assert\_xpath  
[O'Reilly Media - Technology and Business Training](http://tinyurl.com/yrc77g) ← assert\_latest Model

---

<div class="post-metadata">

**Author:** ![Phlip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ed8c4c/32.png) [@Phlip](https://www.ruby-forum.com/u/Phlip)\
**Post date:** [August 22, 2007, 5:49pm UTC](https://www.ruby-forum.com/t/activerecord-crashes-on-include-and-limit-is-there-a-fix/112731/2 "2007-08-22T17:49:44Z")

</div>

Hi –

On Wed, 22 Aug 2007, Phlip wrote:

> Frog.find( :all, :include =\> { :species =\> [‘clade’] },  
> :conditions =\> [‘clade\_id in (?)’, 1],  
> :limit =\> 12 )
> 
> That produces this:
> 
> ActiveRecord::StatementInvalid: Mysql::Error: Unknown column  
> ‘clade\_id’ in ‘where clause’: SELECT id FROM frogs WHERE (clade\_id in  
> (1)) LIMIT 12

Does it work if you change clade\_id to species.clade\_id?

David

–

- Books:  
RAILS ROUTING (new! [http://www.awprofessional.com/title/0321509242](http://www.awprofessional.com/title/0321509242))  
RUBY FOR RAILS ([Ruby for Rails](http://www.manning.com/black))
- Ruby/Rails training  
& consulting: Ruby Power and Light, LLC ([http://www.rubypal.com](http://www.rubypal.com))

---

<div class="post-metadata">

**Author:** ![Phlip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ed8c4c/32.png) [@Phlip](https://www.ruby-forum.com/u/Phlip)\
**Post date:** [August 22, 2007, 6:16pm UTC](https://www.ruby-forum.com/t/activerecord-crashes-on-include-and-limit-is-there-a-fix/112731/3 "2007-08-22T18:16:50Z")

</div>

dblack wrote:

> > Frog.find( :all, :include =\> { :species =\> [‘clade’] },  
> > :conditions =\> [‘clade\_id in (?)’, 1],  
> > :limit =\> 12 )

> Does it work if you change clade\_id to species.clade\_id?

That was it! Thanks!

I didn’t think that would work because the SELECT statement was so  
totally broken. That didn’t indicate pilot error to me.

(Also it’s habtm, so it’s clades\_species.clade\_id…)

And now a _lot_ of code that’s doing a heckuva job is about to get  
downsized.

with\_scope rules!

BTW we have both of these… (-;

> - Books:  
> RAILS ROUTING (new! [http://www.awprofessional.com/title/0321509242](http://www.awprofessional.com/title/0321509242))  
> RUBY FOR RAILS ([Ruby for Rails](http://www.manning.com/black))
> - Ruby/Rails training  
> & consulting: Ruby Power and Light, LLC ([http://www.rubypal.com](http://www.rubypal.com))

–  
Phlip  
[http://www.oreilly.com/catalog/9780596510657/](http://www.oreilly.com/catalog/9780596510657/)  
^ assert\_xpath  
[O'Reilly Media - Technology and Business Training](http://tinyurl.com/yrc77g) ← assert\_latest Model
