Bouncy Melons 0.2
declarative style orm
list.php
<?php
namespace bm\example;
/*
* declare list of bottles
*/
class WineBottles extends \bm\DataList {
/*
* overridde abstract method \bm\DataList::createSingle()
* to create single bottle object
*/
public function createSingle() {
return new WineBottle();
}
/*
* setup view name, optional, by default class name with siffix _view will be used
* winebottles_view in our case
*/
public function getViewName() {
return "my_view";
}
/*
* change default view, to add calculated fields, see single.php
*/
public function declareView() {
/*
* init another table to be joined
*/
$brands = new Brands();
/*
* create or modify view
*/
$this->createViewAs("
SELECT
tBottles.*, FLOOR(RAND()*100) AS `random`,
tBrands.title AS `brand`, tBrands.id AS `brand_id`
FROM
`".$this->getTableName()."` as tBottles
LEFT JOIN
`".$brands->getTableName()."`as tBrands ON (
tBottles.brand = tBrands.id
)
");
}
}