:include doesn't work with v. 2.3.5.1

26 views
Skip to first unread message

MikeMarsian

unread,
Feb 16, 2012, 10:21:27 AM2/16/12
to compos...@googlegroups.com
Hi,
I'm having a problem with :includes when using composite_primary_keys v. 2.3.5.1 (with Rails v.2.3.10)

I have two models:

------
class Member < ActiveRecord::Base
  set_primary_keys :id, :user_id 
  has_many :member_tags,  :foreign_key => [:id, :user_id ]
end

class MemberTag < ActiveRecord::Base
  belongs_to :member, :foreign_key => [:id, :user_id]
end

---------
now, when doing a simple query:  MemberTag.all(:conditions=>{:user_id=>38, :tag=>"consider_follow"},:include=>:member)
I get an error:

NoMethodError: undefined method `id,user_id' for #<MemberTag:0x719a600>
        from C:/Tools/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.10
/lib/active_record/attribute_methods.rb:260:in `method_missing'
        from C:/Tools/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.10
/lib/active_record/association_preload.rb:320:in `send'
        from C:/Tools/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.10
/lib/active_record/association_preload.rb:320:in `preload_belongs_to_ass
ociation'
        from C:/Tools/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.10
/lib/active_record/association_preload.rb:319:in `each'
        from C:/Tools/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.10
/lib/active_record/association_preload.rb:319:in `preload_belongs_to_ass
ociation'
        from C:/Tools/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.10
/lib/active_record/association_preload.rb:120:in `send'
        from C:/Tools/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.10
/lib/active_record/association_preload.rb:120:in `preload_one_associatio
n'
        from C:/Tools/Ruby187/lib/ruby/gems/1.8/gems/activesupport-2.3.1
0/lib/active_support/ordered_hash.rb:115:in `each'
        from C:/Tools/Ruby187/lib/ruby/gems/1.8/gems/activesupport-2.3.1
0/lib/active_support/ordered_hash.rb:115:in `each'
        from C:/Tools/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.10
/lib/active_record/association_preload.rb:114:in `preload_one_associatio
n'
        from C:/Tools/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.10
/lib/active_record/association_preload.rb:91:in `preload_associations'
        from C:/Tools/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.10
/lib/active_record/association_preload.rb:90:in `preload_associations'
        from C:/Tools/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.10
/lib/active_record/association_preload.rb:90:in `each'
        from C:/Tools/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.10
/lib/active_record/association_preload.rb:90:in `preload_associations'
        from C:/Tools/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.10
/lib/active_record/base.rb:1584:in `find_every'
        from C:/Tools/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.10
/lib/active_record/base.rb:619:in `find'
        from C:/Tools/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.10
/lib/active_record/base.rb:639:in `all'
        from (irb):1


Any help will be appreciated, thanx!
< :tag=>"consider_follow"}, :include=>:member)
NoMethodError: undefined method `id,user_id' for #<MemberTag:0x702b448>
        from C:/Tools/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.10
/lib/active_record/attribute_methods.rb:260:in `method_missing'
        from C:/Tools/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.10
/lib/active_record/association_preload.rb:320:in `send'
        from C:/Tools/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.10
/lib/active_record/association_preload.rb:320:in `preload_belongs_to_ass
ociation'
        from C:/Tools/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.10

cfis

unread,
Mar 16, 2012, 4:25:20 AM3/16/12
to Composite Keys for ActiveRecord
Hi Mike,

Sorry, but older versions of cpk aren't supported any longer. You
could take a look at the unit tests and see if any match your
problem. But unfortunately you're on your own for an older version...

Thanks,

Charlie

On Feb 16, 9:21 am, MikeMarsian <mike.po...@gmail.com> wrote:
> Hi,
> I'm having a problem with :includes when using composite_primary_keys v.
> 2.3.5.1 (with Rails v.2.3.10)
>
> I have two models:
>
> ------
> class Member < ActiveRecord::Base
>   set_primary_keys :id, :user_id
>   has_many :member_tags,  :foreign_key => [:id, :user_id ]
> end
>
> class MemberTag < ActiveRecord::Base
>   belongs_to :member, :foreign_key => [:id, :user_id]
> end
>
> ---------
> now, when doing a simple query:  MemberTag.all(:conditions=>{:user_id=>38,
> :tag=>"consider_follow"},:include=>:member)
> I get an error:
>
> *NoMethodError: undefined method `id,user_id' for #<MemberTag:0x719a600>*
Reply all
Reply to author
Forward
0 new messages