Greg Hauptmann
2009-Jan-12 06:10 UTC
What''s a good way to specify set of records to be created across multiple models (with associations)? (e.g. XML, YAML, Ruby code [e.g. hash/array] other?)
Hi, I need to be able to specify for my application, via a configuration approach (i.e. power user, no nice UI required), a way to automate creation of a pre-determine set of database records across a few models. So I''ll try to explain as best I can: * Assume I have a model hierarchy something like the following (basically allocating a back account item out): - model "Bank Account Item" can have multiple - model "Allocation"s and within each allocation it defines .amount (for the allocation, total for each allocation needs to equal bank_account) .person_id (link to existing person in the Person table/model) .category_id (link to existing category in the Category table/model) * There will be an automation routine that will say, "if you see a bank account item with a description of XYZ, then automatically set up it''s allocation to People & Categories" (i.e. predefined). This could be as simple as an "Automation" model that has a regex that would be used, and then a string to store the association(s) that should be created (e.g. XML, or YAML, or Ruby code, i.e. the reason for the question). * An example for what this string might represent for say an automation record where the regex was "Telephone Bill" might be: --------example--------- * Association 1 - amount = 30% (calculates absolute amount on the fly) - person_id = 1 <Person A''s id> - category_id = 23 <work expense> * Association 2 - amount = 70% (calculates absolute amount on the fly) - person_id = 1 <Person A''s id> - category_id = 3 <personal communications expense> --------example--------- Any suggestions re (a) a nice generic way to do this and (b) what format may be the best (e.g. XML, Ruby code, YAML). Some ideas that come to mind: [1] Ruby code that takes input (not great) [2] Ruby code that describes "example" above in the form of Array or Hashes. Maybe best? [3] XML - readable, but a little more code to import? [4] YAML - not that readable, but easy to import [4] Other? thanks -- Greg http://blog.gregnet.org/ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Mikel Lindsaar
2009-Jan-12 11:04 UTC
Re: What''s a good way to specify set of records to be created across multiple models (with associations)? (e.g. XML, YAML, Ruby code [e.g. hash/array] other?)
On Mon, Jan 12, 2009 at 5:10 PM, Greg Hauptmann <greg.hauptmann.ruby-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I need to be able to specify for my application, via a configuration > approach (i.e. power user, no nice UI required), a way to automate creation > of a pre-determine set of database records across a few models. So I''ll > try to explain as best I can:Can''t remember the library names... but you want to look for a "factory" of some sort. -- http://lindsaar.net/ Rails, RSpec and Life blog.... --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Greg Hauptmann
2009-Jan-12 20:03 UTC
Re: What''s a good way to specify set of records to be created across multiple models (with associations)? (e.g. XML, YAML, Ruby code [e.g. hash/array] other?)
I''m more interested in how the routine (albeit in a Factory or not works) actually - e.g. best way of storing the info: xml, ruby code, yaml?? On Mon, Jan 12, 2009 at 9:04 PM, Mikel Lindsaar <raasdnil-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > On Mon, Jan 12, 2009 at 5:10 PM, Greg Hauptmann > <greg.hauptmann.ruby-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > I need to be able to specify for my application, via a configuration > > approach (i.e. power user, no nice UI required), a way to automate > creation > > of a pre-determine set of database records across a few models. So I''ll > > try to explain as best I can: > > Can''t remember the library names... but you want to look for a > "factory" of some sort. > > -- > http://lindsaar.net/ > Rails, RSpec and Life blog.... > > > >-- Greg http://blog.gregnet.org/ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---