ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:activerecord:active_record_tutorial

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
activerecord:active_record_tutorial [2015/12/08 05:15] – [tableKeyHasMany] mnewnhamv5:activerecord:active_record_tutorial [2016/01/13 02:15] – ↷ Page moved from activerecord:active_record_tutorial to v5:activerecord:active_record_tutorial mnewnham
Line 58: Line 58:
 <WRAP right box round> <WRAP right box round>
 == See Also == == See Also ==
-[[userguide:error_handling|Error Handling In ADOdb]]+[[v5:userguide:error_handling|Error Handling In ADOdb]]
 </WRAP> </WRAP>
 ===== Inserting and Updating a Record ===== ===== Inserting and Updating a Record =====
Line 78: Line 78:
   1048: Column 'favorite_color' cannot be null   1048: Column 'favorite_color' cannot be null
    
-This error occurred because MySQL rejected the INSERT query that was generated by ADOdb_Active_Record.+This error occurred because MySQL rejected the INSERT statement that was generated.
  
 To insert a new ADOdb_Active_Record in the database, populate all of ADOdb_Active_Record's properties so that they satisfy the constraints of the database table, and then call the [[activerecod:save()]] method: To insert a new ADOdb_Active_Record in the database, populate all of ADOdb_Active_Record's properties so that they satisfy the constraints of the database table, and then call the [[activerecod:save()]] method:
Line 190: Line 190:
  
 ===== Error Handling and Debugging ===== ===== Error Handling and Debugging =====
-The ADOdb Active Record can be used in conjunction with [[userguide:error_handling|ADOdb error handling]].+The ADOdb Active Record can be used in conjunction with [[v5:userguide:error_handling|ADOdb error handling]].
  
 <code php> <code php>
Line 318: Line 318:
 ===== Transactions ===== ===== Transactions =====
 <WRAP right box 200px> <WRAP right box 200px>
-More about [[reference:reference_guide#transaction_scoping|Transaction Handling]]+More about [[v5:reference:index#transaction_scoping|Transaction Handling]]
 </WRAP> </WRAP>
 The default transaction mode in ADOdb is autocommit. So that is the default with active record too. The general rules for managing transactions still apply. Active Record to the database is a set of insert/update/delete statements, and the db has no knowledge of active records. The default transaction mode in ADOdb is autocommit. So that is the default with active record too. The general rules for managing transactions still apply. Active Record to the database is a set of insert/update/delete statements, and the db has no knowledge of active records.
Line 337: Line 337:
 ===== ClassHasMany ===== ===== ClassHasMany =====
  
-To globally define a one-to-many relationship we use the static function ADODB_Active_Record::ClassHasMany($class, $relation, $foreignKey = ' ', $foreignClass = 'ADODB_Active_Record'). For example, we have 2 tables, persons (parent table) and children (child table) linked by persons.id = children.person_id. The variable $person->children is an array that holds the children. To define this relationship:+To globally define a one-to-many relationship we use the static function [[activerecord:classHasMany()]]. For example, we have 2 tables, persons (parent table) and children (child table) linked by persons.id = children.person_id. The variable $person->children is an array that holds the children. To define this relationship:
  
 <code php> <code php>
Line 408: Line 408:
 var_dump($p->children); var_dump($p->children);
 </code> </code>
-The solution to the above is to unset($p->children) before $p->Load('id=2').+The solution to the above is to  
 +  unset($p->children)  
 +before  
 +  $p->Load('id=2').
  
 ===== TableHasMany ===== ===== TableHasMany =====
Line 425: Line 428:
 <code php> <code php>
  
-$db->Execute("insert into children (person_id,name_first,name_last) values (1,'Jill','Lim')"); +$db->Execute("insert into children (person_id,name_first,name_last)  
-$db->Execute("insert into children (person_id,name_first,name_last) values (1,'Joan','Lim')"); +              values (1,'Jill','Lim')"); 
-$db->Execute("insert into children (person_id,name_first,name_last) values (1,'JAMIE','Lim')");+$db->Execute("insert into children (person_id,name_first,name_last)  
 +               values (1,'Joan','Lim')"); 
 +$db->Execute("insert into children (person_id,name_first,name_last) 
 +               values (1,'JAMIE','Lim')");
  
 class person extends ADOdb_Active_Record{} class person extends ADOdb_Active_Record{}
Line 452: Line 458:
     echo "OK Loaded HasMany<br>";     echo "OK Loaded HasMany<br>";
 else { else {
-    echo "Error loading hasMany should have 3 array elements Jill Joan Jamie<br>";+    echo "Error loading hasMany should have  
 +          3 array elements Jill Joan Jamie<br>";
 } }
 </code>  </code> 
v5/activerecord/active_record_tutorial.txt · Last modified: 2022/06/09 18:37 by 3.83.52.90