[CDBI] RE: How do I use deflate?

Eric Busto EBusto at nvidia.com
Fri Jun 1 23:47:08 BST 2007


The advantage to being able to do $host->location_id('Whatever') to
change the location_id in the hosts table, is it looks a lot like
$host->hostname('Hostname').

By being only one method deep, I could write a script that gets a list
of all columns that the Host table has, and access/set them via
$host->$column_name('Value').  Since my application has a whole lot o'
objects, having a generic script to allow people to manipulate these
objects would be quite useful.  The script would then not have to know
the specifics of every object it deals with, just which columns it has,
which it can find out via $object->columns('All').

-----Original Message-----
From: Edward J. Sabol [mailto:sabol at alderaan.gsfc.nasa.gov] 
Sent: Friday, June 01, 2007 3:37 PM
To: Eric Busto
Cc: classdbi at svr02.digitalcraftsmen.net
Subject: Re: How do I use deflate?


> 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
-----------------------------------------------------------------------------------
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.
-----------------------------------------------------------------------------------



More information about the ClassDBI mailing list