Re: DB_DataObject linking tables
| From: | Justin Patrin | Date: | Sun, 12 Dec 2004 01:02:03 +0000 |
| Subject: | Re: DB_DataObject linking tables | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-16183@lists.php.net to get a copy of this message | ||
On Sat, 11 Dec 2004 14:52:24 -0700, Trevan <tdr@cs.byu.edu> wrote:
> I have been looking at the links.ini examples and am wondering if there
> is a way that I could use it with my setup. Right now, I have a
> database that has 2 sets of paired columns. One of columns in the pair
> is the id in a database that tells the second column where its data is.
> Example:
>
> table: inventory
>
> columns id,categoryname,itemid
> row 1,food,10
> row 2,food,9
> row 3,luggage,15
>
> table: food
>
> colums id,item
> row 9,apple
> row 10,banana
>
> table: luggage
> columns id,item,size
> row 15,briefcase,large
>
> In my example, I have the main table inventory that holds all the items
> in my store. The first column, cateregoryname, is the name of different
> tables that hold specific information (since food and luggage have
> different attributes). The itemid is the id of a specific item inside
> of the category table. Right now, I have to look up the inventory table
> for a certain item, get the category that it is in and then look up in
> the category the itemid that I found in inventory. Do you think a
> links.ini file could do it? If not, do you think I could do it with the
> getLink() command? An example would be real helpful. I have looked at
> the documentation but still don't know how I could get at least the
> getLink() command to work.
>
It sounds like you're saying that the table that the field links to is
dependant on another field. This isn't supported by DB_DataObject
directly (and hence, not by the db.links.ini).
However, I think you can use getLink(). Try this:
$inventory = DB_DataObject::factory('inventory');
$inventory->get(1);
$category = $inventory->getLink('itemid', $inventory->categoryname, 'id');
--
Justin Patrin