2017 © Pedro Peláez
 

library axis-extends-behavior

Propel 1.6 behavior that handles DB entity extension

image

axis/axis-extends-behavior

Propel 1.6 behavior that handles DB entity extension

  • Tuesday, January 15, 2013
  • by 7heaven
  • Repository
  • 1 Watchers
  • 1 Stars
  • 63 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

AxisExtendsBehavior

This behavior allows you to declare single table inheritance entities with extended data fields stored to another table., (*1)

Installation

Use Composer. Just add this dependency to your composer.json:, (*2)

  "require": {
    "axis/axis-extends-behavior": "dev-master"
  }

Add behavior to your propel.ini file:, (*3)

...
propel.behavior.axis_extends.class = lib.vendor.axis.axis-extends-behavior.lib.AxisExtendsBehavior
...

Usage

Declaration

Use behavior in your schema:, (*4)

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:, (*5)

// 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

The Versions

15/01 2013

dev-master

9999999-dev https://github.com/e1himself/axis-extends-behavior

Propel 1.6 behavior that handles DB entity extension

  Sources   Download

MIT

The Requires

  • php >=5.2.0

 

extension behavior propel inheritance axis