Created
April 7, 2015 18:53
-
-
Save converge/c8ec74d9ba6bb0d41450 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public function index() | |
{ | |
$this->paginate = [ | |
'contain' => ['Roles'] | |
]; | |
$this->set('users', $this->paginate($this->Users)); | |
$this->set('_serialize', ['users']); | |
} | |
# Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Roles.roles_id' in 'on clause' | |
# | |
# UserTable is: | |
# | |
<?php | |
namespace App\Model\Table; | |
use App\Model\Entity\User; | |
use Cake\ORM\Query; | |
use Cake\ORM\RulesChecker; | |
use Cake\ORM\Table; | |
use Cake\Validation\Validator; | |
/** | |
* Users Model | |
*/ | |
class UsersTable extends Table | |
{ | |
/** | |
* Initialize method | |
* | |
* @param array $config The configuration for the Table. | |
* @return void | |
*/ | |
public function initialize(array $config) | |
{ | |
$this->table('users'); | |
$this->displayField('id'); | |
$this->primaryKey('id'); | |
$this->addBehavior('Timestamp'); | |
$this->hasOne('Roles', [ | |
'foreignKey' => 'roles_id' | |
]); | |
} | |
/** | |
* Default validation rules. | |
* | |
* @param \Cake\Validation\Validator $validator Validator instance. | |
* @return \Cake\Validation\Validator | |
*/ | |
public function validationDefault(Validator $validator) | |
{ | |
$validator | |
->add('id', 'valid', ['rule' => 'numeric']) | |
->allowEmpty('id', 'create') | |
->requirePresence('username', 'create') | |
->notEmpty('username') | |
->requirePresence('password', 'create') | |
->notEmpty('password'); | |
return $validator; | |
} | |
/** | |
* Returns a rules checker object that will be used for validating | |
* application integrity. | |
* | |
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified. | |
* @return \Cake\ORM\RulesChecker | |
*/ | |
public function buildRules(RulesChecker $rules) | |
{ | |
$rules->add($rules->isUnique(['username'])); | |
$rules->add($rules->existsIn(['roles_id'], 'Roles')); | |
return $rules; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment