Is there anyway that I can setup a relationship like this, with these
two tables, having a user that has subscribers, but disallow
duplicates in the subscriptions table?
Because when I do something line the following:
u = User.find(1)
s = Subscription.new
s.user_id = 1
s.subscriber_id = 3
u.subscribers << 2
I end up with the following records in the subscriptions table:
id user_id subscriber_id
1 1 3
2 1 3
Record with id = 1 was there before the above code was run. How can I
set thiings up so that if I add a subscriber that already exists for a
particular user, it doesn't add a duplicate record. Would be nice if
it doesn't complain about trying to add one either and just does
nothing if it's already there. Maybe that's asking too much?
Is there anyway that I can setup a relationship like this, with these
two tables, having a user that has subscribers, but disallow
duplicates in the subscriptions table?
has_many has a :uniq option that might help you out...
:uniq - if set to true, duplicates will be omitted from the collection.
Useful in conjunction with :through.