Cause
Show a column model
<?php
declare (strict_types=1);
namespace app\model;
use think\Model;
/**
* @mixin \think\Model
*/
class Column extends Model
{
public function articles()
{
return $this->belongsToMany(Article::class, 'column_article', 'article_id', 'column_id');
}
public function hasArt($article_id)
{
return $this->articles()->where('id', $article_id)->count();
}
}
Wrong package when using
constraint violation: 1052 Column 'id' in where clause is ambiguous...
The reason for the error is that the relationship model of ThinkPHP does not know which table ID it is,
Here, we need to know which table it belongs to when sorting, so we also need to specify the table name when using it (Note: it needs to be prefixed)
public function hasArt($article_id)
{
return $this->articles()->where('lu_article.id', $article_id)->count();
}
Similar Posts:
- SQL Error: 1064, SQLState: 42000 [Three Methods to Solve]
- [Solved] Modify the column in el-table, causing the browser to report an error: ResizeObserver loop limit exceeded
- [Solved] no such column: id (code 1): , while compiling: DELETE FROM zhangdan WHERE id=?
- Solve the problem of “typeerror: ‘bool’ object is not callable” in flash and Django
- Error: Unknown column ‘*_image_url’ in ‘field list’ [How to Solve]
- You can’t specify target table for update….
- [Solved] EF An error occurred while updating the entries. See the inner exception for details.
- export ‘default’ (imported as ‘mod’) was not found in ‘-!../../../../node_module .vue?vue&type=script&lang=ts&’ (possible exports: __esModule)
- [Solved] Oracle :value too large for column “SCHEMA”.”TABLE”.”COLUMN” (actual: 519, maximum: 500)
- used in key specification without a key length