Skip to content

Instantly share code, notes, and snippets.

@aramis-it
Last active November 20, 2015 10:53
Show Gist options
  • Save aramis-it/9cbc75b132b0a2328e9a to your computer and use it in GitHub Desktop.
Save aramis-it/9cbc75b132b0a2328e9a to your computer and use it in GitHub Desktop.
<?php
class ExamplesUsersTable extends Table
{
public function initialize(array $config)
{
parent::initialize($config);
$this->table('examples_users');
$this->displayField('id');
$this->primaryKey('id');
$this->addBehavior('Timestamp');
$this->belongsTo('Examples', [
'foreignKey' => 'example_id',
'joinType' => 'INNER'
]);
$this->belongsTo('Users', [
'foreignKey' => 'user_id',
'joinType' => 'INNER'
]);
}
########################
class ExamplesTable extends Table
{
public function initialize(array $config)
{
parent::initialize($config);
$this->table('examples');
$this->displayField('id');
$this->primaryKey('id');
$this->addBehavior('Timestamp');
$this->belongsTo('Users', [
'foreignKey' => 'user_id',
'joinType' => 'INNER'
]);
$this->belongsTo('Relations', [
'foreignKey' => 'relation_id',
'joinType' => 'INNER'
]);
$this->belongsToMany('VoteUsers', // changed Users to VoteUsers because conflict belongsTo Users
['className' => 'Users',
'foreignKey' => 'example_id',
'targetForeignKey' => 'user_id',
'joinTable' => 'examples_users'
]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment