openbuildings/jam-materialized-path

This package is abandoned and no longer maintained. No replacement package was suggested.

Materialized path nesting for Jam ORM models

0.1.0 2014-11-03 09:03 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:41:03 UTC


README

Build Status Scrutinizer Code Quality Code Coverage Latest Stable Version

Materialized path nesting for Jam ORM models

Usage

Add this behaviors your Model

class Model_Category extends Jam_Model {

    public static function initialize(Jam_Meta $meta)
    {
        $meta
            ->behaviors(array(
                'materializedpath' => Jam::behavior('materializedpath')
            ));
    }
}

Database Table:

┌─────────────────────────┐
│ Table: Category         │
├─────────────┬───────────┤
│ id          │ ingeter   │
│ name        │ string    │
│ parent_id*  │ integer   │
│ path*       │ string    │
└─────────────┴───────────┘
* Required fields

Methods

It will add "parent" and "children" associations to the repo. The model will get the convenience methods:

Method Description
decendents() Get a query builder collection for all the decendents
ansestors() Get a query builder collection for all the ansestors
is_root() Boolean check if it is root (has parent) or not
is_descendent_of(Jam_Model $parent) Chech if a model is descendant
is_ansestor_of(Jam_Model $child) Chech if model is ansestor
depth() The depth of the item in the hierarchy

License

Copyright (c) 2014, Clippings Ltd. Developed by Ivan Kerin

Under BSD-3-Clause license, read LICENSE file.