[CDBI] Using a TEMP column with has_a?

Jason Bodnar jason at shakabuku.org
Fri Jun 23 23:13:02 BST 2006


We have a set of Class::DBI classes in use so I have to be careful about
changing things because it could break existing code.

Currently, we have a class called PersonItem. It has two foreign keys --
person_id and item_id that reference the person table and the item table. I
wanted to make calls to $person_item->person_id() and $person_item->item_id()
return Person and Item objects, respectively. I know I can do this with
has_a() but that would break existing code that relies upon those methods
returning an integer (the IDs).

Is it possible to use TEMP columns (ie, __PACKAGE__->columns(TEMP => qw(person
item) with has_a()? I read the Mapping section of the POD but don't quite
understand it:

"If the second argument to has_many is turned into a listref of the Classname
and an additional method, then that method will be called in turn on each of
the objects being returned."

What class is the "method" called a part of? The original object or the
Classname specified in the listref?

Basically, I want to be able to call $person_item->person() and have it return
the Person object that has the id of the $person_item's person_id field. I
guess I could just write my own methods and do it manually but thought CDBI
might be able to do it for me ;-)

Thanks,

Jason

--
Jason Bodnar
jason at shakabuku.org
http://www.shakabuku.org

UnWired Buyer. The best way to win on eBay. Period.
http://www.unwiredbuyer.com




More information about the ClassDBI mailing list