Skip to content

Instantly share code, notes, and snippets.

@hutch78
Created May 4, 2016 18:41
Show Gist options
  • Save hutch78/9b112926df4b56cdac717ab58c8df5da to your computer and use it in GitHub Desktop.
Save hutch78/9b112926df4b56cdac717ab58c8df5da to your computer and use it in GitHub Desktop.
# Property model
class Property < ActiveRecord::Base
has_and_belongs_to_many :contacts, -> { uniq }
end
# Contact model
class Contact < ActiveRecord::Base
has_and_belongs_to_many :properties, -> { uniq }
end
# join table is created like so
create_join_table :properties, :contacts do |t|
t.index [:property_id, :contact_id]
end
# how i would like to delete them
@property.contacts.delete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment