src/Model/Table/TokensTable.php
public function buildRules(RulesChecker $rules)
    {
        //Uses validation rules as application rules
        $rules->add(function (Token $entity) {
            $errors = $this->getValidator('default')->errors(
                $entity->extract($this->getSchema()->columns(), true),
                $entity->isNew()
            );
            $entity->setErrors($errors);

            return empty($errors);
        });

        $rules->add($rules->existsIn(['user_id'], 'Users'));

        return $rules;
    }
public function buildRules(RulesChecker $rules)
    {
        //Uses validation rules as application rules
        $rules->add(function (Token $entity) {
            $errors = $this->getValidator('default')->errors(
                $entity->extract($this->getSchema()->columns(), true),
                $entity->isNew()
            );
            $entity->setErrors($errors);

            return empty($errors);
        });

        $rules->add($rules->existsIn(['user_id'], 'Users'));

        return $rules;
    }
public function buildRules ( RulesChecker $ rules ) { //Uses validation rules as application rules $ rules -> add ( function ( Token $ entity ) { $ errors = $ this -> getValidator ( 'default' ) -> errors ( $ entity -> extract ( $ this -> getSchema ( ) -> columns ( ) , true ) , $ entity -> isNew ( ) ) ; $ entity -> setErrors ( $ errors ) ; return empty ( $ errors ) ; } ) ; $ rules -> add ( $ rules -> existsIn ( [ 'user_id' ] , 'Users' ) ) ; return $ rules ; }
Build rules.

It uses validation rules as application rules.
@param Cake\ORM\RulesChecker $rules The rules object to be modified
@return Cake\ORM\RulesChecker
Build rules .