Re: Accessing accessing foreign key without triggering lazy HasA class loading?
[prev]
[thread]
[next]
[Date index for 2005/03/11]
--- gcomnz <gcomnz@xxxxx.xxx> wrote:
> Hi, all,
>
> I'm trying to figure out whether I can access the ID value for a
> foreign key without triggering the loading of the foreign class?
>
> For instance:
>
> __PACKAGE__->table('task');
> __PACKAGE__->columns(All => qw/task_id on_success on_fail/);
> __PACKAGE__->has_a(on_success => 'IL::Task');
> __PACKAGE__->has_a(on_fail => 'IL::Task');
>
> I want to have the option to read the actual ID value of on_success or
> on_fail without triggering another database read. Am I missing
> something really obvious?
You can be happy you are :)
LOW-LEVEL DATA ACCESS
On some occasions, such as when you're writing triggers or
constraint routines, you'll want to manipulate data in a
Class::DBI object without using the usual get() and set()
accessors, which may themselves call triggers, fetch
information from the database, and the like. Rather than
intereacting directly with the hash that makes up a
Class::DBI object (the exact implementation of which may
change in a future release) you should use Class::DBI's
low-level accessors. These appear 'private' to make you
think carefully about using them - they should not be a
common means of dealing with the object.
The object is modelled as a set of key-value pairs, where
the keys are normalized column names (returned by
find_column()), and the values are the data from the
database row represented by the object. Access is via
these functions:
_attrs
@values = $object->_attrs(@cols);
Returns the values for one or more keys.
pjs
__________________________________
Do you Yahoo!?
Make Yahoo! your home page
http://www.yahoo.com/r/hs
|
|
Re: Accessing accessing foreign key without triggering lazy HasA class loading?
Peter Speltz 19:00 on 11 Mar 2005
|