My models looks like:
class Relationship < ActiveRecord::Base
belongs_to :link_type
belongs_to :parent, :polymorphic => true
belongs_to :child, :polymorphic => true
validates_presence_of :link_type_id
# validates_presence_of :parent_id
# validates_presence_of :parent_type
# validates_presence_of :child_id
# validates_presence_of :child_type
end
class Person < ActiveRecord::Base
has_many :parents, :as => :parent, :class_name =>
"Relationship"
has_many :children, :as => :child, :class_name =>
"Relationship"
end
class Company < ActiveRecord::Base
has_many :parents, :as => :parent, :class_name =>
"Relationship"
has_many :children, :as => :child, :class_name =>
"Relationship"
end
The four validates_presence_of lines that are commented out fail when I
do a save. I''m doing this in my controller:
relationship = Relationship.new(:link_type => link_type)
@person.children << relationship
relationship.parent = company
When I do the save, the fields are set properly in the database. Is
this a bug or am I not doing something right?
Thank you for your help
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---