openbuildings / jam-materialized-path
Materialized path nesting for Jam ORM models
Installs: 3
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 14
Forks: 0
Open Issues: 0
Type:kohana-module
Requires
- php: >=5.4.0
- openbuildings/jam: ~0.4.59
Requires (Dev)
This package is not auto-updated.
Last update: 2022-02-01 12:41:03 UTC
README
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.