Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6863717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:49:14+00:00 2026-05-27T02:49:14+00:00

Not exactly an error, but I think I am missing something important here.. class

  • 0

Not exactly an error, but I think I am missing something important here..

 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

So I can do something like:

 user_test.teams << team_test

and I expect that after that I should be able to do something like:

team_test.users 

it will list user_test among all others.. But it does not..

What am I missing?

Thanks!

EDIT::

 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
 => []   
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:49:15+00:00Added an answer on May 27, 2026 at 2:49 am

    This is strange… Are user_test and team_test saved or only initialized?

    1/ the both are saved:

    user_test = User.create
    team_test = Team.create
    user_test.teams << team_test
    user_test.teams # => team_test among others
    team_test.users # => user_test among others
    

    2/ only one is saved:

    a) the saved model is the one which ‘received’ the other:

    user = User.create
    team = Team.new
    user.teams << team
    # team is saved automatically
    user.teams # => team among others
    team.users # => user among others (because team was saved automatically)
    

    b) the saved model is the one which ‘is received’ by the other:

    user = User.new
    team = Team.create
    user.teams << team
    user.teams # => return team
    team.users # => [] (empty array; the 'receiver' is not saved automatically)
    

    3/ none is saved

    user = User.new
    team = Team.new
    users.teams << team
    user.teams # => team but not saved (i.e. id is nil)
    team.users # => [] (empty array)
    

    You might be in case 2.b or in case 3.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Not exactly about programming, but I need help with this. I'm running a development
Not exactly sure how to look this up, but I'm not finding the solution
This is not exactly a programming question, but it's highly related. We are writing
I have a few tables that have similar fields but not exactly the same.
sorry, it's not exactly a programming question, but I am currently in a research
Similar to this thread, but not exactly: How To Cache Information In A Threadsafe
I'm asking this question despite having read similar but not exactly what I want
I'm not exactly sure what question to ask here since I don't know the
I'm not trying to start an argument here, but for whatever reason, it's typically
I'm trying to figure out this error message and I'm not sure what exactly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.