Skip to content

README Example Support Files

Romans Malinovskis edited this page Jun 5, 2016 · 3 revisions
class Model_User extends atk4\data\Model
{
    protected $table = 'user';
    function init() {
        parent::init();

        $this->addField('name');
        $this->addField('is_client', ['type'=>'boolean']);
    }
}
class Model_Client extends Model_User {
    function init() {
        parent::init();

        $this->addField('is_vip', ['type'=>'boolean']);
        $this->addCondition('is_client', true);

        $this->hasMany('Order');
    }
}
class Model_Item extends atk4\data\Model {
    protected $table = 'item';
    function init() {
        parent::init();

        $this->addField('name');
        $this->addField('price', ['type'=>'money']);
    }
}
class Model_Payment extends atk4\data\Model {
    protected $table = 'payment';
    function init() {
        parent::init();

        $this->addField('amount', ['type'=>'money']);
        $this->hasOne('Order');
    }
}
class Model_Order extends atk4\data\Model {
    protected $table = 'order';
    function init() {
        parent::init();

        $this->addField('qty');
        $this->hasOne('Client');  // not User
        $this->hasOne('Item');
        $this->hasMany('Payment');
    }
}