Perhaps an example would best describe my problem:
Schema:
Referral:
actAs: { timestampable: ~ }
columns:
id: { type: integer, primary: true, notnull: true, autoincrement: true, unique: true }
other_stuff: { type: string }
reasonCode: { type: integer }
relations:
ReasonCode: { local: reasonCode, foreign: id, foreignAlias: ReasonCodes }
ReasonCode:
columns:
id: { type: integer, primary: true, notnull: true, autoincrement: true, unique: true }
description: { type: string }
Query (referralTable.class.php):
public function getObjectByReferralId($id){
$q = Doctrine_Query::create()
->select('*')
->from('referral_submissions')
->where('referral_id=?', $id)
->fetchOne();
return $q;
}
Call in template:
<?php
$id = <source of id>;
echo Doctrine_Core::getTable('referral')->getObjectByReferralId($id)->getReasonCode();
?>
The above call in the template to get the reasoncode returns the “description” stored in the ReasonCode table, not the stored id in the Referral table. I need the actual id, not the joined description. What am I missing?
It’s confusing because you named your foreign key with the name of your relation. So when you think you are getting the key, you fetch the relation. And I guess Doctrine do not retrieve the primary key since there is only one field in your
ReasonCodetable, so it returns thedescriptionfield.Try with :
By the way, you also can retrieve the id using the relation:
I think you should define your foreign key like :
reason_code_idinstead ofreason_code. Then your schema will become:And you will be able to retrieve the id using: