Forum: Ruby on Rails What's a good way to specify set of records to be created across multiple models (with associations)

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Greg H. (Guest)
on 2009-01-12 08:11
(Received via mailing list)
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/
Mikel L. (Guest)
on 2009-01-12 13:04
(Received via mailing list)
On Mon, Jan 12, 2009 at 5:10 PM, Greg H.
<removed_email_address@domain.invalid> 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 H. (Guest)
on 2009-01-12 22:05
(Received via mailing list)
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 L. <removed_email_address@domain.invalid>
wrote:

> "factory" of some sort.
>
> --
> http://lindsaar.net/
> Rails, RSpec and Life blog....
>
> >
>


--
Greg
http://blog.gregnet.org/
This topic is locked and can not be replied to.