Re: [CDBI] how to generate a virtual column object from more that one real columns

Alan <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.class-dbi
Message-ID <[email protected]>
On Sat, Mar 10, 2007 at 03:29:41PM -0600, Mike Demoulin wrote:
> Here's what I want to do. I have a table (person) that has, among other
> columns, fname, mname, and lname. I have a Class::DBI subclass (Person) to
> handle that table. I have a class (Name) to encapsulate those 3 values into
> one object. Instead of constructing the Name form Person after each query, I
> would like Person to be able to treate name as a column, and to return a
> Name.

I can think of two solutions:

1 - create a 'name' method in C::Person that does the C::Name lookup.

IE: 
package C::Person;
use blah;
[ set up tables, etc]

sub name {
        my $self = shift;
        my $name = C::Name->search( { person_id => $self->id } );
        return $name; # to return the object or
        return $name->first . " " . $name ->last; # to return string
}

2 - Use view (aggregate table) (postgres has these) to combine the two
tables.


-- 
Alan <[email protected]> - http://arcterex.net
--------------------------------------------------------------------
"Backups are for people who don't pray."                 -- big Mike
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.