Skip to content

Instantly share code, notes, and snippets.

Created January 15, 2018 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/39a3624315d1769b0351c416c48345ef to your computer and use it in GitHub Desktop.
Save anonymous/39a3624315d1769b0351c416c48345ef to your computer and use it in GitHub Desktop.
query on a join table
<?php
//Model ForumPostsTable :
$this->belongsToMany('Subscribers', [
'className' => 'Users',
'targetForeignKey' => 'user_id',
'joinTable' => 'forum_posts_subscribers',
'dependent' => true,
]);
//Later
public function replyNotify($data = null)
{
$result = false;
if(isset($data) && isset($data['forum_post_id']) && isset($data['exception']) && is_array($data['exception'])) {
//Récupération de tous les abonnés;
$query = $this->ForumPostsSubscribers->findByForumPostId($data['forum_post_id']);
$subscribers = $query->toArray();
$result = $Subscribers;
// $result = true;
}
return $result;
}
//Got an error :
Table "App\Model\Table\ForumPostsTable" is not associated with "ForumPostsSubscribers"
//and if I try :
$query = $this->ForumPostsSubscribers->findByForumPostId($data['forum_post_id']);
//then got an error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Subscribers.forum_post_id' in 'where clause'
//How can I access my joinTable?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment