pclib  2.3.2
Lightweight PHP framework
Public Member Functions
Relation Class Reference

It represents related record(s) of the Model. More...

Inheritance diagram for Relation:
Selection BaseObject

Public Member Functions

 __construct (Model $model, $name)
 Constructor. More...
 
 getJoinCondition ()
 
 save (Model $model)
 Save $model as relation of the owner. More...
 
- Public Member Functions inherited from Selection
 rewind ()
 Iterator.rewind() implementation. More...
 
 current ()
 Iterator.current() implementation. More...
 
 key ()
 Iterator.key() implementation. More...
 
 next ()
 Iterator.next() implementation. More...
 
 valid ()
 Iterator.valid() implementation. More...
 
 __call ($name, $args)
 PHP magic method. More...
 
 first ()
 Return first record in the selection. More...
 
 isEmpty ()
 Is Selection empty? More...
 
 count ()
 Return number of rows in the Selection.
 
 sum ($s)
 Return summary of field $s. More...
 
 avg ($s)
 Return AVG of field $s. More...
 
 find ($id)
 Find record by primary key. More...
 
 update (array $values)
 Update records in selection with $values.
 
 delete ()
 Delete selection.
 
 getClone ()
 Clone selection.
 
 limit ($limit, $offset=0)
 Set selection limit. More...
 
 select ($columns)
 Execute selection and return array of rows. More...
 
 from ($s)
 Set source table $s. More...
 
 where ($s)
 Set where condition. More...
 
 whereJoin ($relName, $s)
 Set where condition. More...
 
 order ($s)
 Set order by clausule. More...
 
 group ($s)
 Set group by clausule. More...
 
 having ($s)
 Set having clausule. More...
 
 close ()
 Closes the cursor, enabling the query to be executed again. More...
 
 clear ()
 Clear selection query and data. More...
 
 getSql ()
 Build sql query for current selection. More...
 
 toArray ()
 Return current selection as array. More...
 
 __toString ()
 Return string representation of selection for debugging purposes.
 
- Public Member Functions inherited from BaseObject
 loadDefaults ($className=null)
 Load default parameters of class $className into object instance.
 
 setProperties (array $defaults)
 Set public properties of object from the array. More...
 
 addEvent ($name, $callback)
 Add event handler to $object->$name property. More...
 
 toArray ()
 Convert object to array. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from BaseObject
static defaults ()
 Set or retireve default parameters of the object. More...
 
- Data Fields inherited from Selection
 $db
 var Db
 
- Data Fields inherited from BaseObject
 $onNewInstance
 Occurs when new instance of the class is created. More...
 
 $onMissingMethod
 Occurs when called method does not exist. More...
 
 $serviceLocator
 var function() Return service object when requested with service(). More...
 
- Protected Member Functions inherited from Selection
 newModel ($data)
 Create model instance, fill its values with $data and return it. More...
 
 execute ()
 Execute query to the database and set $this->result. More...
 
- Protected Member Functions inherited from BaseObject
 fireEvent ($name, array $args=array())
 Run all event handlers in $object->$name property. More...
 
 service ($service, $default=null)
 Try acquire $service and load it into property $this->$service. More...
 
- Protected Attributes inherited from Selection
 $query = array()
 Array of sql query clausules. More...
 
 $result = null
 Result of underlying sql query. More...
 
 $data = array()
 Data of the current row. More...
 

Detailed Description

It represents related record(s) of the Model.

Usually you do not instantiate this class manually - it is returned by Model->related() method. Because it is Selection, you can use where(), order() etc. methods on related records. Examples:

Constructor & Destructor Documentation

__construct ( Model  $model,
  $name 
)

Constructor.

Parameters
Model$modelOwner of the relation
string$nameName of the relation - must be specified in model template

Member Function Documentation

getJoinCondition ( )
Returns
string SQL join condition
save ( Model  $model)

Save $model as relation of the owner.

Example: Add post to the user: $user->posts->save($post);

Parameters
Model$modelRecord to be saved.

The documentation for this class was generated from the following file: