-
-
Save anonymous/39a3624315d1769b0351c416c48345ef to your computer and use it in GitHub Desktop.
query on a join table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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