This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

vasdor125884
vasdor125884

Hello,

I've created a Model, its table has fields 'created_by' and 'updated_by'

create_table_file.php

$table->integer('created_by')->unsigned();
$table->integer('updated_by')->unsigned();

I wanted to add to columns.yaml something like this

    created_by:
        label: Author
        relation: user
        select: login
        searchable: true

And when I opened backend form with lists of items got an error: Unknown column 'table_name.user_id' in 'where clause' (SQL: selecttable_name.*, (select login frombackend_userswheretable_name.user_id=backend_users.id) ..

So the problem is that October is looking for user_id column while it should be updated_by or created_by

How can I create a relationship that says that I want to use created_by column instead of user_id

vasdor125884
vasdor125884

Oh, I figured it out . I should've used

public $belongsTo = [
    'user' => ['Backend\Models\User', 'key' => 'created_by']
];

instead of:

public $hasOne = [
    'user' => ['Backend\Models\User', 'key' => 'created_by']
];

Last updated

1-2 of 2

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.