Skip to content
yuki-kimoto edited this page Oct 15, 2012 · 1 revision

Include models

DBIx::Custom Documents >

If needed, you can include models from module files by include_model.

$dbi->include_model('MyModel');

include_model include all models in MyModel namespace. Note that MyModel.pm is always needed.

lib / MyModel.pm
    / MyModel / book.pm
              / company.pm

Model example

MyModel

MyModel example. MyModel generally inherits DBIx::Custom::Model.

package MyModel;
use DBIx::Custom::Model -base;

1;

-base option for inheritance is inherited from Object::Simple.

MyModel::book

MyModel::book example. MyModel::book generally inherits MyModel.

package MyModel::book;
use MyModel -base;

has primary_key => 'book_id';
has ctime => 'created_time';
has mtime => 'modified_time';

has join => sub {
  [
    'left join company on book.company_id = company.id',
    'left join author on book.author_id = author.id'
  ]
}

1;

has is "has" in Object::Simple, which is method to define attribute.

Clone this wiki locally