v5:activerecord:classbelongsto
This is an old revision of the document!
classBelongsTo
Syntax
void ADODB_Active_Record::classBelongsTo( string $class, string $relationName, string $foreignKey, optional string $parentPrimaryKey = 'id', optional string $parentClass = 'ADODB_Active_Record' )
Description
You can define the parent of the current object using ClassBelongsTo()
. In the example below, we have a child table kids, and a parent table person. We have a link kids.person_id = persons.id. We create a child first, then link it to the parent
Usage
class kid extends ADOdb_Active_Record{}; ADODB_Active_Record::ClassBelongsTo('kid','person','person_id','id'); $ch = new kid(); // default tablename will be 'kids', with primary key 'id' $ch->Load('id=1'); $p = $ch->person; if (!$p || $p->name_first != 'John') echo "Error loading belongsTo<br>"; else echo "OK loading BelongTo<br>";
v5/activerecord/classbelongsto.1449324125.txt.gz · Last modified: 2017/04/21 11:21 (external edit)