Hi, How can I populate a table (create several default objects) after a company (an object) is created. I would use after_create inside the Company model but I need to populate a lot of data and I think the model is not a good place. I''m thinking about having the data I want to populate in a yml file and insert it in a table when a company is created using after_create, but I don''t know how to do that. Any hint? Thanks! -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Juan Kinunt wrote:> I would use after_create inside the Company model but I need to populate > a lot of data and I think the model is not a good place.Why is that? It certainly sounds like your creation of a company requires the writing of some additional data, which are effectively default attributes of a company, no? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Juan Kinunt
2010-Jul-13 13:32 UTC
Re: Populate default data in tables when object is created
Ar Chron wrote:> Juan Kinunt wrote: >> I would use after_create inside the Company model but I need to populate >> a lot of data and I think the model is not a good place. > > Why is that? It certainly sounds like your creation of a company > requires the writing of some additional data, which are effectively > default attributes of a company, no?For example, a Company has_many Threats and a Threat belongs_to a Company and I want to populate the table Threats with some default threats when a Company is created. I don''t use the same threats for each company because each company can add, delete and modify their threats as they want, so I don''t want to share threats. If you think this can be done differently better any hint will be really appreciated :) -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Jul-13 13:36 UTC
Re: Populate default data in tables when object is created
Juan Kinunt wrote:> Hi, > > How can I populate a table (create several default objects) after a > company (an object) is created. I would use after_create inside the > Company model but I need to populate a lot of data and I think the model > is not a good place.And I think you''re wrong. :) The model is the right place for logic that has to do with model objects!> I''m thinking about having the data I want to > populate in a yml file and insert it in a table when a company is > created using after_create, but I don''t know how to do that.You''d do it the same way as the first method; just read the YAML file instead of putting the data in the code.> Any hint? > Thanks!Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Juan Kinunt wrote:> For example, a Company has_many Threats and a Threat belongs_to a > Company and I want to populate the table Threats with some default > threats when a Company is created.Precisely! The default action for a ''company creation'' step is to manufacture n threats associated with that company. The behavior of defaulting those records for each company as it is created belongs in the Company model (in my opinion). If you have different ''default'' threats depending on what kind of company is created (threats are dependent on a company attribute), then all the more reason for that defaulting logic to be contained in the company model.> I don''t use the same threats for each > company because each company can add, delete and modify their threats as > they want, so I don''t want to share threats. If you think this can be > done differently better any hint will be really appreciated :)You would create an instance of each desired threat type for each company when the company was created. No threat sharing was intended in my earlier response, sorry for the ambiguity. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.