[CDBI] Re: How do I use deflate?

"Edward J. Sabol" <sabol-2oVx0MVsMgiP/[email protected]> Fri, 1 Jun 2007 18:36:40 -0400
Newsgroups gmane.comp.lang.perl.modules.class-dbi
Message-ID <[email protected]>
> I can update the location_id field for a host just fine like this:
> $host->location_id(1); # or some other location's primary key
>
> I want to be able to update the location_id field for a host like so:
> $host->location_id('SomeLocationName');
>
> From what I have gathered from the docs, I should be able to use deflate
> in has_a to do the translation from SomeLocationName to that location's
> ID/primary key. It seems like it should be as simple as:
> Host->has_a(location_id => 'Location',
>             deflate => 'id');
>
> This should call the Location object's id method before update the
> location_id column of the host table, right? If I'm being an idiot,
> please set me straight.

You shouldn't use deflation for this. The ->location_id() method should
return an object of type Location if you have the has_a() relationship
configured correctly. In order to change the name of the location of $host,
you would then do the following:

$host->location_id->name('WhateverName');

After which, you need to commit the transaction to the database, if you're
using transactions, or issue a ->update() if 'autoupdate' mode is not active.

Hope this helps,
Ed