Skip to content

Instantly share code, notes, and snippets.

@eqdw
Created January 26, 2011 15:43
Show Gist options
  • Save eqdw/796872 to your computer and use it in GitHub Desktop.
Save eqdw/796872 to your computer and use it in GitHub Desktop.
## DOES THIS MAKE SENSE / IS VALID
class Foo < ActiveRecord::Base
has_many :bar
has_many :baz, :through => :bar
end
class Bar < ActiveRecord::Base
belongs_to :baz
end
class Baz < ActiveRecord::Base
end
##Does this make sense? Each bar only has one baz. Each foo has multiple bars. Therefore, each foo has multiple bazs, even though a bar only has one?
@nathanbertram
Copy link

In Foo, you'd want plurals:
has_many :bars ;)
has_many :bazes, :through => :bars (choose a name other than baz haha ;p)

In Bar I'd add foo , so it's
belongs_to :baz
belongs_to :foo

Then in Baz you can do:
has_many :bars
has_many :foos, :through => :bars

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment