[SOLVED] Foreign key relationships in QCubed?

I have created two tables:

create tables cities(

cityID int not null auto_increment,

name varchar(40) not null,

primary key(cityID),

unique key(name));


create table stud(

studID int not null auto_increment,

name varchar(40) not null,

city int not null,

primary key (studID),

key(name),

foreign key (city) references cities(cityID))

 

Now say I want to access city name of a person by its forieign key, how do I do that? I have got so far:

<?php $objStud = Stud::Load(1); ?>

Student ID: <?php _p($objStud->StudID); ?> <br />

Name: <?php _p($objStud->Name); ?> <br />

City: <?php _p($objStud->CityCities->Name); ?> <br /> 

I get the error: Undefined GET property or variable in 'Stud' class: CityCities

All help will be highly appreciated.

Login or Register to comment on this topic.
Filter Comments by:
First Post Replies
Re [Foreign key relationships in QCubed?]:

I guess I know why this is happenning. What you have written in the code is:

<?php $objStud = Stud::Load(1); ?>
Student ID: <?php _p($objStud->StudID); ?> <br />
Name: <?php _p($objStud->Name); ?> <br />
City: <?php _p($objStud->CityCities->Name); ?> <br />

The problem is that you are trying to do $objStud->CityCities->Name in the last line. It should be $objStud->CityObject->Name. Try that and let me know whether it works or not.

Permalink
Login or Register to comment on this topic.