[CDBI] How do I use deflate?
"Eric Busto" <[email protected]> Fri, 1 Jun 2007 15:15:59 -0700
| Newsgroups | gmane.comp.lang.perl.modules.class-dbi |
|---|---|
| Message-ID | <[email protected]> |
Lets say I have two tables:
CREATE TABLE hosts (
host_id INT PRIMARY KEY,
hostname VARCHAR(64),
location_id INT REFERENCES locations
);
CREATE TABLE locations (
location_id INT PRIMARY KEY,
name VARCHAR(16)
);
I have two packages to represent those objects:
package Host;
use base 'MyBaseClass';
Host->table('hosts');
Host->columns(Primary => qw/host_id/);
Host->columns(Essential => qw/hostname location_id/);
Host->has_a(location_id => 'Location');
package Location;
use base 'MyBaseClass';
Location->table('locations');
Location->columns(Primary => qw/location_id/);
Location->columns(Essential => qw/name/);
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.
Thanks.
-Eric
-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain
confidential information. Any unauthorized review, use, disclosure or distribution
is prohibited. If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------