I have a User model and a Tracker model
the goal is to have a user having: - one tracker that was created by this user - one referer tracker to the user
On the other hand, each tracker: - belong to one user, the one one who created it - have many user referees (who ever used this开发者_C百科 tracker as a referer)
So I built my model the following way:
class User
.
.
references_one :referer_tracker, :class_name => "Tracker", :inverse_of => :referees
references_one :tracker, :class_name => "Tracker", :inverse_of => :owner
.
.
end
class Tracker
.
.
belongs_to :owner, :class_name => "User", :inverse_of => :tracker
has_many :referees, :class_name => "User", :inverse_of => :referer_tracker
.
.
end
The User.tracker / Tracker.owner relationship works just fine. But I can't get the User.referer_tracket // Tracker.referees one to work.
With the console if do something like this:
trackerX.referees << userX
trackerX.save
=> false because of invalid referees
on the other end if I try to do: userX.referer_tracker = trackerX I get an error: NoMethodError: undefined method `entries' for #
I am running out of ideas to try... I am running RoR 3.03 and Mongoid 2.0.0.rc.7
Thanks,
Alex
精彩评论