Forum: Ruby on Rails has many through not working in ruby-enterprise

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
8e6b444d982b2bd8eb71113ef336a10f?d=identicon&s=25 mirec (Guest)
on 2009-03-24 02:31
(Received via mailing list)
hi,
I have simple has many through association which is working without
problem on ruby 1.8.6 and rails 2.0.2, but on ruby-enterprise with
ruby 2.0.2 or 2.3.2 it just does not see "through" part of
association.

class User < ActiveRecord::Base
  has_many :userships
  has_many :user_groups, :through => :userships
end
class UserGroup < ActiveRecord::Base
  has_many :userships
  has_many :users, :through => :userships
end
class Usership < ActiveRecord::Base
  belongs_to :user
  belongs_to :user_group
end


as i am moving app to new server, i am getting these errors:

ActiveRecord::StatementInvalid: Mysql::Error: Unknown column
'user_groups.user_id' in 'where clause': SELECT * FROM `user_groups`
WHERE (`user_groups`.user_id = 8)
  from /usr/local/ruby-enterprise/lib/ruby/gems/1.8/gems/
activerecord-2.3.2/lib/active_record/connection_adapters/
abstract_adapter.rb:212:in `log'
  from /usr/local/ruby-enterprise/lib/ruby/gems/1.8/gems/
activerecord-2.3.2/lib/active_record/connection_adapters/
mysql_adapter.rb:320:in `execute'
  from /usr/local/ruby-enterprise/lib/ruby/gems/1.8/gems/
activerecord-2.3.2/lib/active_record/connection_adapters/
mysql_adapter.rb:595:in `select'
  from /usr/local/ruby-enterprise/lib/ruby/gems/1.8/gems/
activerecord-2.3.2/lib/active_record/connection_adapters/abstract/
database_statements.rb:7:in `select_all_without_query_cache'
  from /usr/local/ruby-enterprise/lib/ruby/gems/1.8/gems/
activerecord-2.3.2/lib/active_record/connection_adapters/abstract/
query_cache.rb:62:in `select_all'
  from /usr/local/ruby-enterprise/lib/ruby/gems/1.8/gems/
activerecord-2.3.2/lib/active_record/base.rb:661:in `find_by_sql'
  from /usr/local/ruby-enterprise/lib/ruby/gems/1.8/gems/
activerecord-2.3.2/lib/active_record/base.rb:1553:in `find_every'
  from /usr/local/ruby-enterprise/lib/ruby/gems/1.8/gems/
activerecord-2.3.2/lib/active_record/base.rb:615:in `find'
  from /usr/local/ruby-enterprise/lib/ruby/gems/1.8/gems/
activerecord-2.3.2/lib/active_record/associations/
association_collection.rb:60:in `find'
  from /usr/local/ruby-enterprise/lib/ruby/gems/1.8/gems/
activerecord-2.3.2/lib/active_record/associations/
association_collection.rb:395:in `find_target'
  from /usr/local/ruby-enterprise/lib/ruby/gems/1.8/gems/
activerecord-2.3.2/lib/active_record/associations/
association_collection.rb:349:in `load_target'
  from /usr/local/ruby-enterprise/lib/ruby/gems/1.8/gems/
activerecord-2.3.2/lib/active_record/associations/association_proxy.rb:
139:in `inspect'

obviously, association is not correctly understood by ruby and
"through" part of it is not taken

anybody having similar problem? any ideas?
8e6b444d982b2bd8eb71113ef336a10f?d=identicon&s=25 mirec (Guest)
on 2009-03-24 17:04
(Received via mailing list)
forgot to mention

as i am moving app to new server where i am testing it with REE, i am
getting these errors:

happens on this line on User model:
self.user_groups.include?(UserGroup.find(gr))
8e6b444d982b2bd8eb71113ef336a10f?d=identicon&s=25 mirec (Guest)
on 2009-03-24 17:16
(Received via mailing list)
now i found in console, that it works in development mode, also
running from mongrel is fine

>> u=User.find(8)
=> #<User id: 8, .....

>> u.user_groups
=> [#<UserGroup id: 1, name: ......
8e6b444d982b2bd8eb71113ef336a10f?d=identicon&s=25 mirec (Guest)
on 2009-03-24 18:25
(Received via mailing list)
now this is one of the weirdest

action which has:

logger.info curent_user.user_groups.inspect

in itself runs properly
This topic is locked and can not be replied to.