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

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

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/
^ assert_xpath
http://tinyurl.com/yrc77g <-- assert_latest Model

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

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… (-;


Phlip
http://www.oreilly.com/catalog/9780596510657/
^ assert_xpath
http://tinyurl.com/yrc77g <-- assert_latest Model

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs