openbuildings / jam-materialized-path
此包已被废弃,不再维护。未建议替代包。
为 Jam ORM 模型提供的物化路径嵌套
0.1.0
2014-11-03 09:03 UTC
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
为 Jam ORM 模型提供的物化路径嵌套
使用方法
将此行为添加到您的模型中
class Model_Category extends Jam_Model { public static function initialize(Jam_Meta $meta) { $meta ->behaviors(array( 'materializedpath' => Jam::behavior('materializedpath') )); } }
数据库表
┌─────────────────────────┐
│ Table: Category │
├─────────────┬───────────┤
│ id │ ingeter │
│ name │ string │
│ parent_id* │ integer │
│ path* │ string │
└─────────────┴───────────┘
* Required fields
方法
它将为 repo 添加 "parent" 和 "children" 关联。模型将获得便利的方法
方法 | 描述 |
---|---|
descendents() | 获取所有后代查询构建器集合 |
ancestors() | 获取所有祖先查询构建器集合 |
is_root() | 布尔检查是否为根(有父级)或不是 |
is_descendent_of(Jam_Model $parent) | 检查模型是否为后代 |
is_ancestor_of(Jam_Model $child) | 检查模型是否为祖先 |
depth() | 项目在层次结构中的深度 |
许可证
版权所有 (c) 2014, Clippings Ltd。由 Ivan Kerin 开发
根据 BSD-3-Clause 许可证,请参阅 LICENSE 文件。