This is my systems usage:
PHP Code:
// empty object
$user = new User();
// load object
$user = new User(5);
// change object
$user['name'] = 'bob';
$user['password'] = 'foo';
$user->profile->description = 'new profile info';
// save/update to db
try {
$user->save();
} catch(Exception $e) {
$e->getMessage();
}
// Find objects
$users = User::find(array('name'=>'bob'));
// Find objects
$users = User::find(array('name'=>'bob','pwd'=>'foo'));
// Find objects
$users = User::find(array('user_id IN'=>array(1,2,3)));
// get linked objects 1:1 (run-time joining)
$users = user::find(array('include'=>'profile','id'=>3));
// get linked objects 1:1 (lazy)
echo $user->profile->description;
// get linked objects 1:1 (gateway)
echo $user->getProfile()->description;
// get linked objects 1:n (run-time joining)
$user = user::find(array('include'=>'messages','id'=>3));
// get linked objects 1:n (lazy)
echo $user->messages[3]->title
// get linked objects (gateway)
$messages = $user->getMessages(array('limit'=>20,'offset'=>20));
$messages[3]->title;
Usage of dynamic columns:
PHP Code:
// order users by year created
$users = User::find(
array(
'dynamic'=>array(
'user_year'=>'YEAR({this}.created)'
)
,'sort'=>array(
'user_year'=>'DESC'
)
)
);
$users[3]->user_year;
More practical Use (counting number of messages per user):
PHP Code:
// order users by year created
$users = User::find(
array(
'dynamic'=>array(
'message_total'=>'COUNT(Message.id)'
,'user_year'=>'YEAR({this}.created)'
)
,'sort'=>array(
'user_year'=>'DESC'
)
,'include'=>array(
'messages'
)
,'group'=>'id'
)
,array(
'require'=>false
)
);
$users[3]->message_total;
Here is another fun one. This would retrieve all the blogs comments with with a limit and offset. All in a single query.
PHP Code:
$subquery = BlogComment::find(
,'subquery'
,array(
'status <>'=>0
,'blog_id'=>89
,'limit'=>20
,'offset'=>19
)
);
$blog = Blog::find(
,'one'
,array(
'include'=>$subquery
,'id'=>89
)
,array(
'require'=>false
,'association'=>array(
'id'=>'t0_blog_id'
)
,'rename'=>'comments'
,'propertyType'=>'many'
)
);
foreach($blog->comments) {
...
}
Bookmarks