I am extending Rainlab\Blog\Models\Post.
I used post_id as primary key in the table, and did not use an extra id column.
Schema::create('ut_ut_extendposts', function($table)
{
$table->engine = 'InnoDB';
$table->integer('post_id')->unsigned();
$table->boolean('closed')->default(false);
$table->primary('post_id');
$table->timestamps();
});
In the extended Post model:
public $belongsTo = [
'post' => ['RainLab\Blog\Models\Post','post_id','id']
];
In Plugin.php
Post::extend(function($model) {
$model->hasOne['extendpost'] = ['Ut\Ut\Models\Extendpost', 'id', 'post_id'];
});
When I use the extend Post model (in backend list), the following error occurs:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'extendposts.id' in 'group statement' (SQL: select extendposts.*, rainlab_blog_posts.title as title from extendposts left join rainlab_blog_posts on rainlab_blog_posts.id = extendposts.post_id group by extendposts.id order by title desc)
The problem seems to be the 'group by' clause. How could I solve it without adding 'id' column to the table?
Last updated