* Users Model
*
* @property \Cake\ORM\Association\BelongsTo $UserTypes
+ * @property \Cake\ORM\Association\HasMany $Reviews
+ * @property \Cake\ORM\Association\BelongsToMany $RelationshipsSoftwares
+ * @property \Cake\ORM\Association\BelongsToMany $Relationships
*/
class UsersTable extends Table
{
parent::initialize($config);
$this->table('users');
- $this->displayField('id');
+ $this->displayField('username');
$this->primaryKey('id');
$this->addBehavior('Timestamp');
-
+
//For upload file -> avatar
$this->addBehavior('Josegonzalez/Upload.Upload', [
'photo' => [
'path' => 'webroot{DS}files{DS}{model}{DS}{field}{DS}{primaryKey}{DS}avatar',
],
]);
-
-
+
$this->belongsTo('UserTypes', [
'foreignKey' => 'user_type_id',
'joinType' => 'INNER'
]);
+ $this->hasMany('Reviews', [
+ 'foreignKey' => 'user_id'
+ ]);
+// $this->belongsToMany('RelationshipsSoftwares', [
+// 'foreignKey' => 'user_id',
+// 'targetForeignKey' => 'relationships_software_id',
+// 'joinTable' => 'relationships_softwares_users'
+// ]);
+// $this->belongsToMany('Relationships', [
+// 'foreignKey' => 'user_id',
+// 'targetForeignKey' => 'relationship_id',
+// 'joinTable' => 'relationships_users'
+// ]);
}
/**
->allowEmpty('username');
$validator
- ->allowEmpty('logo_url');
+ ->allowEmpty('logo_directory');
$validator
->allowEmpty('url');
$validator
->requirePresence('password', 'create')
->notEmpty('password');
-
+
$validator
- ->requirePresence('email', 'create')
- ->notEmpty('email');
-
+ ->add('email', 'valid', ['rule' => 'email'])
+ ->allowEmpty('email');
+
+ $validator
+ ->allowEmpty('photo');
+
return $validator;
}
public function buildRules(RulesChecker $rules)
{
$rules->add($rules->isUnique(['username']));
+ $rules->add($rules->isUnique(['email']));
$rules->add($rules->existsIn(['user_type_id'], 'UserTypes'));
return $rules;
}
-
}