Skip to content

Instantly share code, notes, and snippets.

@myobie
Created December 10, 2008 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myobie/34471 to your computer and use it in GitHub Desktop.
Save myobie/34471 to your computer and use it in GitHub Desktop.
# 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