#Using ORM Classes
Basic API
There are two ways to instantiate an ORM class:
new Orm_TableName($id=null)
Quad_Orm::get($table, $id=null)
Data may be accessed and set using assignment or method. e.g.:
$user = Quad_Orm::get('user');
// 3 ways to set a field
$user->first_name = 'John';
$user->setFirstName('John');
$user->properties(array('first_name'=>'John'));
// 3 ways get a field
$user->first_name == 'John'; // true
$user->getFirstName() == 'John'; // true
$user->properties() == array('first_name'=>'John'); // trueset() and get() methods may be overridden to pre- and post-process data. e.g.:
public function setFirstName($name) {
$this->_data['first_name'] = ucwords($name); // PREFERRED
$this->first_name = ucwords($name); // BAD: will cause an infinite loop
$this->first_name_soundex = soundex($name); // OK to set other properties
return $this;
}Public methods inherited from Quad_Orm and Quad_MagicProperties:
- construct($id = null) Create a blank record or get record with primary key equal to $id
- data() Get all fieldvalues in an array
- delete($keepProperties=false, $keepSerial=false) Clear data and delete record from database if applicable
- db() Get the handle to the database
- clear() Unset all data values
- columns() Get the list of column names
- hasChanged($field=null) Return true if $field has changed or if any fields have changed
- isInDb() Return true if record exists in db
- limitToColumns($data) Return an array which contains only fields that are known column names
- load($criteria) Load data based on the first record matching the given criteria
- loadId($id=null) Load data based on the primary key value
- onChange($property, $oldValue) Called after any property is set or unset
- pk() Get the column names of which the primary key is composed
- preSleep(&$props) Add, modify or remove properties before sleeping
- properties($values=null) Get or set properties from an array
- revert() Discard any changed values and reload from database
- save() Insert or update the record
- table() Get the table name
- tableModel() Get the table model used for table operations