axis / axis-extends-behavior
This package is abandoned and no longer maintained.
No replacement package was suggested.
Propel 1.6 behavior that handles DB entity extension
dev-master
2013-01-15 10:28 UTC
Requires
- php: >=5.2.0
This package is not auto-updated.
Last update: 2020-08-21 17:41:01 UTC
README
This behavior allows you to declare single table inheritance entities with extended data fields stored to another table.
Installation
Use Composer. Just add this dependency to your composer.json
:
"require": { "axis/axis-extends-behavior": "dev-master" }
Add behavior to your propel.ini file:
...
propel.behavior.axis_extends.class = lib.vendor.axis.axis-extends-behavior.lib.AxisExtendsBehavior
...
Usage
Declaration
Use behavior in your schema:
my_page: id: ~ title: { type: varchar } body: { type: varchar, size: 3000 } type: { type: varchar } _inheritance: column: type # Note: the classes map should be empty to allow extending this class from any plugins # without modification of main schema.yml file. # Of course, you can constrain inheritance classes defining key-classes map here if you want. classes: {} # note that extension table name (my_product_page_data) doesn't match # .. generated additional class name (MyProductPage). This is important. my_product_page_data: id: { primaryKey: true, type: integer, foreignTable: my_page, foreignReference: id, onDelete: cascade, required: true } product_id: { type: integer, foreignTable: my_product, foreignReference: id, onDelete: restrict } _propel_behaviors: axis_extends: { class_name: MyProductPage, extends: my_page }
This schema will generate following classes:
// main entity AR class class MyPage extends BaseMyPage { /* ... */ } // extended entity AR class class MyProductPage extends BaseMyProductPage { /* ... */ } // extended entity base class extends main entity class class BaseMyProductPage extends MyPage { /* ... */ } // extended entity additional fields object stored to `my_product_page_data` class MyProductPageData extends BaseMyProductPageData { /* ... */ }
Usage
$myPage = new MyPage(); $myPage->setTitle('Regular page'); $myPage->setBody('Hello world!'); $myPage->save(); // stores 1 row to 'my_page' table $productPage = new MyProductPage(); $productPage->setTitle('Product page'); // sets 'my_page.title' field $productPage->setBody('It\'s a product page! Hooray!'); // sets 'my_page.body' field // seamless extended fields access $productPage->setProductId($product->getId()); // sets 'my_product_page_data.product_id' field $productPage->save(); // stores 1 row to 'my_page' table and 1 row to 'my_product_page_data' table