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:in `select'' 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:in `select_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:in `find_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:in `find'' Any ideas? Roland -- Posted via http://www.ruby-forum.com/.
Roland Mai wrote:> 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''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 Mai <roland.mai@gmail.com> wrote:> > 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:in > `select'' > 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:in > `select_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:in > `find_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:in > `find'' > > 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060815/b3f4f419/attachment.html
Maybe Matching Threads
- Rails AR/SQLServer Unit Test: [6912] failed (but getting better)
- [PATCH] Support for DB Clusters/Replication in ActiveRecord (RFC)
- Eager Loading with custom :finder_sql
- [AR] #{id} namespace visibility used in finder_sql
- Trouble combining :has_many, :finder_sql and :conditions to create a sub-search