[CDBI] Re: How do I use deflate?
Edward J. Sabol
sabol at alderaan.gsfc.nasa.gov
Sat Jun 2 00:25:31 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
> 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').
Unfortunately, Class::DBI just doesn't work that way (out of the box).
Class::DBI is very extensible, however, so you're free to develop your own
Class::DBI::Relationship class to replace HasA or you could extend your Host
class with a hand-written method that does what you want.
might_have() does something like what you want already. Although the
semantics of might_have() differ slightly from has_a() (1:0+1 vs. 1:1),
there's no reason why you can't use that relationship instead:
Unless it changed in Class::DBI v3.0.x, the pseudo-column(s) added via
might_have() do not get returned by $object->columns('All'), however. I once
submitted a patch which added support for $object->columns('MightHave') for
similar reasons to what you describe, but it never got incorporated due to
changes in the Class::DBI::Relationship API. You could easily extend the
columns() method though to do something like that. I wouldn't suggest messing
with 'All' though. I'd be afraid changing 'All' might break CDBI internals.
I'd make it 'All+' or 'Everything' or something like that. You can use the
meta_info() method for relationship-related introspection. Try dumping it:
print Dumper My::CDBI::Class->meta_info();
or, for just the might_have relationships:
print Dumper My::CDBI::Class->meta_info('might_have');
Hope this helps,
More information about the ClassDBI