2017 © Pedro Peláez
 

lithium-library li3_fake_model

Lithium PHP alternative (fast) model implementation

image

blainesch/li3_fake_model

Lithium PHP alternative (fast) model implementation

  • Wednesday, January 7, 2015
  • by BlaineSch
  • Repository
  • 3 Watchers
  • 8 Stars
  • 16,510 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 9 Versions
  • 0 % Grown

The README.md

Lithium Fake Model

For those times when you don't want a real one, (*1)

Build Status, (*2)

This library is for the PHP Lithium Web Framework and provides an alternative to its built-in data models., (*3)

It doesn't do much, but that's kinda the point. Here's a comparison:, (*4)

Lithium Models Fake Models
Dirty Attributes yes no
Filterable (AOP) yes no
Schema Definition yes no
Uses LI3 Data Sources yes yes [1]
Works with SQL and Mongo yes maybe [2]
Model-level Relationships no yes

[1] Sort of. We wrap the native LI3 data source in our own to avoid the Document/DocumentSet madness., (*5)

[2] I've only tested with MongoDB, but Fake Models could be adjusted to work with a SQL data source if someone wants to make the effort., (*6)

Then why would I use this?

You probably shouldn't. I mean, Fake Models do basically nothing! No one in their right mind would make the switch., (*7)

OK, to be honest, Lithium Models are bloated and they're slow. They store lots of redundant data, and all the filterable methods (I suspect) contribute to their slowness., (*8)

Here are some benchmarks..., (*9)

Count Lithium Models Fake Models
first() 1 76ms 32ms
all() 100 2863ms 78ms

Each test was with 100 iterations (divide each by 100 to get true timing)., (*10)

Relationships

Lithium models support relationships at the data source layer, which works fine for relational databases, but not for MongoDB., (*11)

Fake models support relationships at the model level and efficiently eager-loads related records by issuing extra queries. Here's how you use it:, (*12)

1. Define your model relationships., (*13)

class Posts extends Model {

  public $hasMany = array(
    'Comments' => array(
      'to'        => 'Comments',  // The model
      'key'       => array('_id' => 'comment_id'), // or, you can use an array of foreign keys, e.g. array('comment_ids' => '_id')
      'fieldName' => 'comments',  // The key it's on
      // `order`, `limit`, `conditions` can also be used
    ),
  );

}

2. Query your model and tell it which relationships to fetch., (*14)

$posts = Posts::all(array(
  'with' => array('Comments')
));

The above query will:, (*15)

  1. query and fetch all the posts
  2. issue a second query to get all the comments
  3. connect the child comments onto the appropriate parent posts

Relationships can also provide deep query logic:, (*16)

$posts = Posts::all(array(
  'with' => array(
    'comments' => array(
      'order' => array('date' => 'asc'),
      'limit' => 10,
      'conditions' => array(
        'flagged' => false,
      ),
    ),
));

Relationships can also be nested further, e.g.:, (*17)

$posts = Posts::all(array(
  'with' => array(
    'Comments' => array('Author')
  )
));

This method call still only issues 3 total queries to the Mongo database, yipee!, (*18)

Fake model is licensed under the MIT License - see the LICENSE file for details, (*19)

The Versions

07/01 2015

dev-master

9999999-dev https://github.com/BlaineSch/li3_fake_model

Lithium PHP alternative (fast) model implementation

  Sources   Download

MIT

The Requires

 

models lithium li3 relations

07/01 2015

0.2.2

0.2.2.0 https://github.com/BlaineSch/li3_fake_model

Lithium PHP alternative (fast) model implementation

  Sources   Download

MIT

The Requires

 

models lithium li3 relations

28/07 2014

0.2.1

0.2.1.0 https://github.com/BlaineSch/li3_fake_model

Lithium PHP alternative (fast) model implementation

  Sources   Download

MIT

The Requires

 

models lithium li3 relations

10/07 2014

0.2.0

0.2.0.0 https://github.com/BlaineSch/li3_fake_model

Lithium PHP alternative (fast) model implementation

  Sources   Download

MIT

The Requires

 

models lithium li3 relations

12/04 2014

0.1.4

0.1.4.0 https://github.com/BlaineSch/li3_fake_model

Lithium PHP alternative (fast) model implementation

  Sources   Download

GNU GENERAL PUBLIC LICENSE

The Requires

 

models lithium li3 relations

16/01 2014

0.1.3

0.1.3.0 https://github.com/BlaineSch/li3_fake_model

Lithium PHP alternative (fast) model implementation

  Sources   Download

GNU GENERAL PUBLIC LICENSE

The Requires

 

models lithium li3 relations

28/08 2013

0.1.2

0.1.2.0 https://github.com/BlaineSch/li3_fake_model

Lithium PHP alternative (fast) model implementation

  Sources   Download

GNU GENERAL PUBLIC LICENSE

The Requires

 

models lithium li3 relations

28/08 2013

0.1.1

0.1.1.0 https://github.com/BlaineSch/li3_fake_model

Lithium PHP alternative (fast) model implementation

  Sources   Download

GNU GENERAL PUBLIC LICENSE

The Requires

  • php >=5.3

 

models lithium li3 relations

15/08 2013

0.1

0.1.0.0 https://github.com/BlaineSch/li3_fake_model

Lithium PHP alternative (fast) model implementation

  Sources   Download

GNU GENERAL PUBLIC LICENSE

The Requires

  • php >=5.3

 

models lithium li3 relations