/**
* Initialize method
*
* @param array $config The configuration for the Table.
* @return void
*/
public function initialize(array $config)
{
parent::initialize($config);
$this->table('members');
$this->belongsToMany('Teams', ['through' => 'TeamMemberships', 'dependent' => true]);
$this->belongsToMany('Games', ['through' => 'GameMemberships', 'dependent' => true]);
// $this->belongsToMany('Tos',
// [
// 'through' => 'Friendships',
//// 'joinTable'=>'Friendships',
//// 'foreignKey'=>'id',
// 'foreignKey'=>'to_id',
// 'className'=>'Members',
//// 'queryBuilder' => function (Query $q) {
//// return $q->where(['Friends.from_id == Members.id']); // Full conditions for filtering
//// }
// ]
// );
// $this->belongsToMany('Froms',
// [
// 'through' => 'Friendships',
//// 'joinTable'=>'Friendships',
//// 'foreignKey'=>'id',
// 'targetForeignKey'=>'from_id',
// 'className'=>'Members',
//// 'queryBuilder' => function (Query $q) {
//// return $q->where(['Friends.from_id == Members.id']); // Full conditions for filtering
//// }
// ]
// );
$this->addBehavior('Search.Search');
// $this->addBehavior('CounterCache', [
// 'Friends' => [
// 'friend_count' => function (Event $event, Entity $entity, Table $table) {
// $query = $table->find('all')->where([
// 'to_id' => $entity->get('id')
// ])->orWhere(['from_id'=>$entity->get('id')]);
// return $query->count();
// }
// ]
// ]);
//
$this->searchManager()->add('q', 'Search.Like', ['before' => true, 'after' => true, 'field' => [$this->aliasField('first_name'), $this->aliasField('last_name')]]);
$this->isValidateEmail = true;
}