Has_many + finder_sql & :include

Hello,

In a model I have:

has_many :things, :finder_sql => ’ select * from other_things ’ +
’ where id = #{id} ’

When I do MyClass.find(:all, :include => :things) I get a weird error:

from
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/abstract_adapter.rb:120:in
log' from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/sqlserver_adapter.rb:485:inselect’
from
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/sqlserver_adapter.rb:233:in
select_all' from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/associations.rb:1110:inselect_all_rows’
from
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/associations.rb:975:in
find_with_associations' from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/associations.rb:973:infind_with_associations’
from
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:923:in
find_every' from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:381:infind’

Any ideas?

Roland

Roland M. wrote:

c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/abstract_adapter.rb:120:in
`log’

It’s not possible to include a collection that has a custom finder SQL.

You’ll have make the whole query a custom MyClass.find_by_sql query,
using the http://mrj.bpa.nu/eager_custom_sql.rb mod to attach the
OtherThing objects to the MyClass objects.

But is your custom SQL the same as specifying the :class_name to be
‘OtherThings’, and the :foreign_key to be ‘id’?


We develop, watch us RoR, in numbers too big to ignore.

On 8/15/06, Roland M. [email protected] wrote:

from
`select_all’
/lib/active_record/associations.rb:973:in
Any ideas?
Using :finder_sql rules out all the other sql modifiers since Rails
doesn’t
know how to parse and modify the SQL you provide. This does deserve a
clear
error message.

jeremy

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