ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:activerecord:belongsto

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Last revisionBoth sides next revision
activerecord:belongsto [2015/12/05 15:34] – created mnewnhamactiverecord:belongsto [2015/12/05 15:41] mnewnham
Line 6: Line 6:
 <WRAP right box> <WRAP right box>
 ==Syntax== ==Syntax==
-  void ADODB_Active_Record::BelongsTo(+  void belongsTo(
     string $relationName,      string $relationName, 
     string $foreignKey,      string $foreignKey, 
Line 19: Line 19:
 class Child extends ADOdb_Active_Record{}; class Child extends ADOdb_Active_Record{};
 $ch = new Child('children',array('id')); $ch = new Child('children',array('id'));
-$ch->BelongsTo('person','person_id','id');  ## this can be simplified to $ch->BelongsTo('person'+/* 
-                                            ## as foreign key defaults to $table.'_id' and +this can be simplified to $ch->BelongsTo('person'
-                                            ## parent pkey defaults to 'id'+as foreign key defaults to $table.'_id' and 
 +parent pkey defaults to 'id' 
 +*/ 
 +$ch->BelongsTo('person','person_id','id');  
 $ch->Load('id=1'); $ch->Load('id=1');
 $p = $ch->person; $p = $ch->person;
-if (!$p || $p->name_first != 'John') echo "Error loading belongsTo<br>"; +if (!$p || $p->name_first != 'John' 
-else echo "OK loading BelongTo<br>";+    echo "Error loading belongsTo<br>"; 
 +else  
 +    echo "OK loading BelongTo<br>";
 </code> </code>
v5/activerecord/belongsto.txt · Last modified: 2016/01/13 02:15 by mnewnham