承接 axis/axis-extends-behavior 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

axis/axis-extends-behavior

Composer 安装命令:

composer require axis/axis-extends-behavior

包简介

Propel 1.6 behavior that handles DB entity extension

README 文档

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

统计信息

  • 总下载量: 69
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2012-12-08