Skip to content
Browse files

updated

  • Loading branch information...
1 parent bf1dcd5 commit 7960931f49c08c4349117aa6e1e5071f6bd2c788 @scottkf committed Oct 31, 2011
View
10 ...ails-3--self-referential-has_many--through-parent---child-relationship-modelling.markdown
@@ -19,14 +19,14 @@ Srsly, that's more of an SEO title than anything, because damnit, I know how the
rails new confusingTitleProject
cd confusingTitleProject
rails g model Person name:string
-rails g model ParentRelationship parent_id:integer child_id:integer
+rails g model PersonRelationship parent_id:integer child_id:integer
{%endhighlight%}
{% highlight ruby %}
-#App/Models/ParentRelationship.rb
-class ParentRelationship < ActiveRecord::Base
+#App/Models/PersonRelationship.rb
+class PersonRelationship < ActiveRecord::Base
belongs_to :parent, :class_name => "Person"
belongs_to :child, :class_name => "Person"
end
@@ -37,15 +37,15 @@ class Person < ActiveRecord::Base
validates_presence_of :first_name, :last_name
has_many :parent_child_relationships,
- :class_name => "ParentRelationship",
+ :class_name => "PersonRelationship",
:foreign_key => :child_id,
:dependent => :destroy
has_many :parents,
:through => :parent_child_relationships,
:source => :parent
has_many :child_parent_relationships,
- :class_name => "ParentRelationship",
+ :class_name => "PersonRelationship",
:foreign_key => :parent_id,
:dependent => :destroy
has_many :children,

0 comments on commit 7960931

Please sign in to comment.
Something went wrong with that request. Please try again.