Skip to content

Instantly share code, notes, and snippets.

@sheldonbaker
Last active August 29, 2015 14:00
Show Gist options
  • Save sheldonbaker/11058884 to your computer and use it in GitHub Desktop.
Save sheldonbaker/11058884 to your computer and use it in GitHub Desktop.
class Company < ActiveRecord::Base
has_many :users
end
class User < ActiveRecord::Base
belongs_to :company
end
class Thing < ActiveRecord::Base
belongs_to :company
has_many :users # Can I somehow validate that only users.@each.company_id == self.company_id?
validate :users_belong_to_same_company # Or do I need a custom validation method?
def user_ids=(user_ids)
# Or do I need to do it here?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment