Virtual Foreign Key via codegen_settings.xml

thread: 4 messages  |  last: a year ago  |  started: tuesday, december 18, 2007, 9:57 am pst


#1  |  stromee (Minneapolis, MN) United States of America
Tuesday, December 18, 2007, 9:57 AM PST

Hi,

I have set up a virtual foreign key via codegen_settings.xml like this:

            <relationships><![CDATA[
            cart_order_details.order_id => cart_orders.id
            transaction.order_id =>cart_orders.id
            ]]></relationships>

The classes are created, but how can I access the related class objects like the following?

<?php
$objTransaction 
Transaction::Load(1);
echo 
$objTransaction->CartOrders->CustomerFirstName;
die();
?>

This doesn't work, but if I define my foreign key as an SQL statement using InnoDB, that code works just fine.  Am I not able to access data like this if I use a Virtual Foreign Key?

This is the first time I've used Virtual Foreign Key's so if anyone has info on this or has used this before and can help me, I would appreciate it.

Thanks much,
Chris

#2  |  stromee (Minneapolis, MN) United States of America
Tuesday, December 18, 2007, 10:01 AM PST

Wow, that works great, I actually just mistyped something.  Fixed it.

#3  |  w. Patrick Gale (Chapel Hill, NC) United States of America
Monday, January 30, 2012, 4:20 PM PST

I just tried using virtual foreign keys for the first time today (trying to split up tables between two database instead of one) and I am wondering if there is a trick to getting the virtual keys to generate linking objects like they do when you define foreign keys between tables in a single database?

In other words, if I have table 'form' that has a foreign key to 'user' table (both in the same database with foreign keys defined in the database), I can access the user object from a form object ($objForm->User); so I get a User object generated within the Form data class for me.  However if I split the two tables between databases and use virtual foreign keys within the codegen_settings.xml file all I get is a UserId property generated in the Form data class and not a reference to the User node.

Can the codegen generate the User objects/nodes in my Form data class using virtual foreign keys or is that not coded into the functionality?

many thanks

#4  |  Mike Ho (San Diego, CA) United States of America Qcodo Administrator
Tuesday, January 31, 2012, 8:08 AM PST

Unfortunately, not if the tables are in two different databases.

The current implementation of codegen only allows you to define the relationships within a database... but of course, you could likely poke around in the code and make mods to it so that it can recognize and start to gen across different databases.



Copyright © 2005 - 2013, Quasidea Development, LLC
This open-source framework for PHP is released under the terms of The MIT License.