In my app, User objects can follow each other, and be followed. The two
relationships are distinct.

I'm seeing that when I set `user_a.follows << user_b` that
`user_b.followed_by.count` still == 0. Why?

When I play in the console, I see:

$ jordan =>"Jordan")
=> #<User id: nil, name: "Jordan">
$ matt =>"Matt")
=> #<User id: nil, name: "Matt">
$ matt.followers << jordan
=> [#<User id: nil, name: "Jordan">]
$ matt.followers.first
=> #<User id: nil, name: "Jordan">
$ jordan.friends.first
=> nil

SQL (14.1ms) INSERT INTO "users" ("name") VALUES (?) [["name",
SQL (0.3ms) INSERT INTO "users" ("name") VALUES (?) [["name",
SQL (0.4ms) INSERT INTO "followings" ("followee_id", "follower_id")
VALUES (?, ?) [["followee_id", nil], ["follower_id", 2]]
=> true


My objects are defined as:

class User < ActiveRecord::Base
has_many :follower_followee_rel,
:class_name => "Following",
:foreign_key => 'followee_id',
:dependent => :destroy
has_many :friends,
:through => :follower_followee_rel,
:source => :followee
has_many :followee_follower_rel,
:class_name => 'Following',
:foreign_key => 'follower_id',
:dependent => :destroy
has_many :followers,
:through => :followee_follower_rel,
:source => :follower

class Following < ActiveRecord::Base
belongs_to :followee,
:class_name => 'User'
belongs_to :follower,
:class_name => 'User'

Totally ignoring the second half of the relationship.

No errors are raised. What's going on?

Posted via

You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 3 | next ›
Discussion Overview
grouprubyonrails-talk @
postedSep 18, '11 at 6:26p
activeSep 19, '11 at 10:03a



site design / logo © 2021 Grokbase