Created
December 17, 2013 03:24
-
-
Save bayendor/7999530 to your computer and use it in GitHub Desktop.
Always use :inverse_of to connect two models in a belongs_to/has_many relationship. When you have two models in a belongs_to/has_many relationship, you should always use the :inverse_of option to tell ActiveRecord that they're two sides of the same association. By setting this option, Rails can optimize object loading so forum and forum.posts[0]…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Forum < ActiveRecord::Base | |
has_many :posts, :inverse_of => :forum | |
end | |
class Post < ActiveRecord::Base | |
belongs_to :forum, :inverse_of => :posts | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment