Не совсем ошибка, но я думаю, что я здесь упускаю что-то важное ..
class Team < ActiveRecord::Base
has_many :groups
has_many :users, :through => :groups
class User < ActiveRecord::Base
acts_as_authentic
has_many :groups
has_many :teams, :through => :groups
class Group < ActiveRecord::Base
belongs_to :user
belongs_to :team
Так что я могу сделать что-то вроде:
user_test.teams << team_test
, и я ожидаю, что после этогоЯ должен быть в состоянии сделать что-то вроде:
team_test.users
он будет перечислять user_test среди всех других .. Но это не так ..
Чего мне не хватает?
Спасибо!
РЕДАКТИРОВАТЬ ::
ruby-1.9.3-p0 :001 > user_test = User.create
(0.0ms) SAVEPOINT active_record_1
(0.1ms) SELECT 1 FROM "users" WHERE "users"."persistence_token" = '6f2890df599776198476630fad3db57b62606339d7ec2c1e96cc4081919789fa0a7cac5ffaed6b8f61f28f3ff2abd6ca890eb623c1b2d6718328d10527fa1566' LIMIT 1
(0.0ms) ROLLBACK TO SAVEPOINT active_record_1
=> #<User id: nil, username: nil, email: nil, crypted_password: nil, password_salt: nil, persistence_token: "6f2890df599776198476630fad3db57b62606339d7ec2c1e96c...", created_at: nil, updated_at: nil>
ruby-1.9.3-p0 :002 > team_test = Team.create
(0.0ms) SAVEPOINT active_record_1
SQL (1.9ms) INSERT INTO "teams" ("created_at", "name", "personal", "project_id", "updated_at", "visible") VALUES (?, ?, ?, ?, ?, ?) [["created_at", Tue, 22 Nov 2011 23:09:28 UTC +00:00], ["name", nil], ["personal", false], ["project_id", nil], ["updated_at", Tue, 22 Nov 2011 23:09:28 UTC +00:00], ["visible", nil]]
(0.0ms) RELEASE SAVEPOINT active_record_1
=> #<Team id: 8, name: nil, created_at: "2011-11-22 23:09:28", updated_at: "2011-11-22 23:09:28", visible: nil, personal: false, project_id: nil>
ruby-1.9.3-p0 :003 > user_test.teams << team_test
(0.1ms) SAVEPOINT active_record_1
(0.0ms) RELEASE SAVEPOINT active_record_1
=> [#<Team id: 8, name: nil, created_at: "2011-11-22 23:09:28", updated_at: "2011-11-22 23:09:28", visible: nil, personal: false, project_id: nil>]
ruby-1.9.3-p0 :004 > user_test.teams
=> [#<Team id: 8, name: nil, created_at: "2011-11-22 23:09:28", updated_at: "2011-11-22 23:09:28", visible: nil, personal: false, project_id: nil>]
ruby-1.9.3-p0 :005 > team_test.users
User Load (0.1ms) SELECT "users".* FROM "users" INNER JOIN "groups" ON "users"."id" = "groups"."user_id" WHERE "groups"."team_id" = 8
=> []