-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use helper to generate behavior config array.
- Loading branch information
Showing
3 changed files
with
63 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
namespace App\Model\Table; | ||
|
||
use Cake\ORM\Query; | ||
use Cake\ORM\RulesChecker; | ||
use Cake\ORM\Table; | ||
use Cake\Validation\Validator; | ||
|
||
/** | ||
* Posts Model | ||
* | ||
* @method \App\Model\Entity\Post get($primaryKey, $options = []) | ||
* @method \App\Model\Entity\Post newEntity($data = null, array $options = []) | ||
* @method \App\Model\Entity\Post[] newEntities(array $data, array $options = []) | ||
* @method \App\Model\Entity\Post|bool save(\Cake\Datasource\EntityInterface $entity, $options = []) | ||
* @method \App\Model\Entity\Post patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = []) | ||
* @method \App\Model\Entity\Post[] patchEntities($entities, array $data, array $options = []) | ||
* @method \App\Model\Entity\Post findOrCreate($search, callable $callback = null, $options = []) | ||
* | ||
* @mixin \Cake\ORM\Behavior\CounterCacheBehavior | ||
* @mixin \Cake\ORM\Behavior\TranslateBehavior | ||
*/ | ||
class PostsTable extends Table | ||
{ | ||
|
||
/** | ||
* Initialize method | ||
* | ||
* @param array $config The configuration for the Table. | ||
* @return void | ||
*/ | ||
public function initialize(array $config) | ||
{ | ||
parent::initialize($config); | ||
|
||
$this->setPrimaryKey('id'); | ||
|
||
$this->addBehavior('CounterCache', [ | ||
'Users' => ['post_count'] | ||
]); | ||
$this->addBehavior('Translate', [ | ||
'defaultLocale' => 'fr_FR' | ||
]); | ||
} | ||
|
||
/** | ||
* Returns the database connection name to use by default. | ||
* | ||
* @return string | ||
*/ | ||
public static function defaultConnectionName() | ||
{ | ||
return 'test'; | ||
} | ||
} |