/** * */ public function categories() { return $this->belongsToMany("AudioCategoryModel", "portal_category_post", "category_id", "post_id"); }
id=27, is 27 records of the content table
$id = $this->request->param("id", 0, "intval"); $AudioPostModel = new AudioPostModel(); $post = $AudioPostModel->where("id", $id)->find(); $postCategories = $post->categories()->alias("a")->column("a.name", "a.id"); $postCategoryIds = implode(",", array_keys($postCategories)); dump($postCategoryIds); dump($postCategories);
data from dump
string(5) "10,11"
array(2) {
[10] => string(12) ""
[11] => string(12) ""
}
Classification Table
27id
originally the intermediate table post_id is associated with the id, of the content table. Now I want to modify the post_id of the post_id, content table of the post_id associated content table to be a timestamp.
the whole execution logic should first take the data whose post_id is equal to id filtered out by the id of the content table in the intermediate table, and then look up the resulting category_id to the classification table to get the corresponding name.
however, I can"t find the first step in the above code, that is, to find the intermediate table data with the content table id, so there is no way to find the data through post_id.