Skip to content

Instantly share code, notes, and snippets.

@myobie

myobie/snippet.rb

Created Dec 10, 2008
Embed
What would you like to do?
# Solved!
class Thing
# these associations are fine
belongs_to :user
belongs_to :assigned_user, :class_name => "User", :child_key => [:assigned_user_id]
# this is not working
has n, :subscriptions
has n, :subscribers, :through => :subscriptions, :class_name => 'User', :child_key => [:ticket_id], :remote_name => :user
end
class Subscription
belongs_to :thing
belongs_to :user
end
class User
has n, :things
end
@thing = Thing.create
3.times do
@thing.subscriptions.create :user => User.create
end
@thing.subscriptions.reload.length # => 3
@thing.subscribers.reload.length #=> 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment