On 1/4/06 4:50 PM, "John Siracusa" <[EMAIL PROTECTED]> wrote:
> On 1/4/06, Sean Davis <[EMAIL PROTECTED]> wrote:
>> I haven't seen a "find_or_create" method anywhere. I know there is a good
>> reason why there isn't one (if there isn't one). It seems like a useful
>> method to have when creating new related objects in multiple tables. Before
>> I naively write my own, why is there not such a method?
>
> It's not really needed in end-user code when using RDBO, IME, and I
> try hard to keep the method namespace of Rose::DB::Object as empty as
> possible. As for creating new related objects, just let the parent
> object methods do it for you.
>
> Here's an abbreviated example from the deep-joins.t test:
>
> $product =
> $Product->new(
> id => 1,
> name => 'Kite',
> vendor =>
> {
> id => 1,
> name => 'V1',
> region => { id => 'DE', name => 'Germany' }
> },
> prices =>
> [
> { price => 1.23, region => { id => 'US', name => 'America' } },
> { price => 4.56, region => { id => 'DE', name => 'Germany' } },
> ]);
>
> $product->save; # the magic happens here
>
> That save() will "find/attach or create" the associated Vendor,
> Region, and Price objects while saving the Product object (all in the
> correct order, all within a transaction where supported). You can go
> as many levels deep as you want. Just look in deep-joins.t, there are
> some hairy examples that go up to 7 levels deep.
WOW!!!
> http://search.cpan.org/src/JSIRACUSA/Rose-DB-Object-0.601/t/deep-joins.t
>
> If you can give me a specific example of where you need to use
> find_or_create() and the normal relationship methods don't cut it,
> then I'll consider adding it (as load_or_create() or maybe
> load_or_save() probably).
Nope. You are correct as usual. I have some messy data and I was trying to
get away without specifying a primary key based on the data itself--wrong
way to go. I have to do some major cleaning....
Sean
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object