On Mar 10, 2:46 pm, Mo Al <[email protected]> wrote:
> Hi
>
> I am getting a Stack level too deep error when i try creating a new
> critical process object:
>
> here is the code:
>
> class Role < ActiveRecord::Base
>   has_many :authorizations
>   has_many :critical_processes, :through => :authorizations
>   has_many :assignments
>   has_many :users, :through => :assignments
> end
>
> class CriticalProcess < ActiveRecord::Base
>   has_many :authorizations
>   has_many :roles, :through => :authorizations, :dependent => :destroy,
> :primary_key => :cp_secondary_id
>
>   after_create :new_cp
>
>   def create_roles
>     self.roles.create :name => "#{self.cp_title} edit",
> :critical_process_id => self.id, :edit => true, :review => false
>     self.roles.create :name => "#{self.cp_title} review",
> :critical_process_id => self.id, :edit => false, :review => true
>   end
>
>   def set_secondary_id
>       self.update_attribute :cp_secondary_id, self.id

This is the problem - internally, update_attribute calls save on the
Role object while it's still in the first save transaction and
new_record? is still set. This triggers the after_create callback
again, and boosh - you've got a stack overflow.

I don't think the :primary_key option is going to work on the :through
association, though; what does the Authorization join model look like,
and how are the three linked together?

--Matt Jones

-- 
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