Master Chief wrote:
> I am trying to create a record with association.  Within the create
> method, I would also like to pre-populate dependent (has_many) records
> from a template in the database.

I'm not exactly clear what you're doing, but here are some
comments that may help.

>    1. class PrototypeModel < ActiveRecord::Base
>    2.   belongs_to :author, :class_name => 'User'
>    3.   has_many :departments
>    4.   belongs_to :prototype_model
>    5.   acts_as_tree :foreign_key => "parent_id"
>    6. end
> 
>    1. class Department < ActiveRecord::Base
>    2.   validates_presence_of :name, :description
>    3.   validates_presence_of :parent_id
>    4.   acts_as_tree :foreign_key => "parent_id"
>    5.   belongs_to :department
>    6.   belongs_to :prototype_model
>    7. end

1. Are the two belongs_to associations that reference their
    own class necessary, or can you use the parent association
    generated by acts_as_tree?

2. You should use "validates_presence_of :parent" instead.
    Using the foreign key will prevent validation when the
    parent is new.  You have to make sure that either
    (1), the foreign-key is non-NULL and points to an existing
    record, or (2), that a new parent object is assigned to the
    association.

-- 
Rails Wheels - Find Plugins, List & Sell Plugins - http://railswheels.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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to