k1low/has_no

Simple binding model practice plugin for CakePHP.

Fund package maintenance!
k1LoW

Installs: 4 022

Dependents: 1

Suggesters: 0

Security: 0

Stars: 7

Watchers: 2

Forks: 0

Open Issues: 0

Type:cakephp-plugin

3.0.1 2015-10-30 03:07 UTC

This package is auto-updated.

Last update: 2024-04-06 08:23:11 UTC


README

This plugin support following binding model practice.

Bake and write bind property on model file. unbindModel() all. bindModel() you want to.

Features

  • unbindModel() all by Model::belongsTo, Model::hasOne, Model::hasMany, Model::hasAndBelongsToMany.
  • Provide simple bind model method has(), hasAll() by Model::belongsTo, Model::hasOne, Model::hasMany, Model::hasAndBelongsToMany.

!!!!!NOTICE!!!!!

HasNo >= 3.x

Containable based

HasNo 2.x

Property modifiy based

Usage

Add the following code in whichever model you want to unbindModel() all (ex. Post Model).

<?php
class Post extends Model {
    public $actsAs = array('HasNo.HasNo');

    public $hasMany = array(
        'Comment' => array(
            'className' => 'Comment',
            'foreignKey' => 'post_id',
            'dependent' => false,
        )
    );

    public $hasAndBelongsToMany = array(
        'Tag' => array(
            'className' => 'Tag',
            'joinTable' => 'posts_tags',
            'foreignKey' => 'post_id',
            'associationForeignKey' => 'tag_id',
            'unique' => true,
        )
    );

}

And if you want to use model's bind property, use method $this->Post->has('Comment') , $this->Post->has(array('Comment', 'Tag')) or $this->Post->hasAll() .

License

under MIT License