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

jan.blazek8327461
jan.blazek8327461

Hello. I get an "Internal server error" when i use same column name in my model as is in the database.

In database i have 2 entities - Category with columns ID and Name, Task with columns ID, name and category_ID. In my CMS model i have entity "Task" with field type of "Relation" with name "category_id" - look up to model "Category" to column "ID".

In my Task.php i add: public $belongsTo = [ 'category_id' => ['me\Task\Models\Category', 'key' => 'category_id', 'otherKey' => 'id'] ];

When i try to update Task in "Task editor" i get "Internal server error" with no other message. I figure out that problem is in assign of value to "$model->category_id" in "setModelAttributes" in "FormModelServer.php". If i assign to $model->category_id anything (if i hardcode it) i got same error.

Easy solution is to rename column name "category_id" in model of "Task" to anything else (and in $belongsTo too). Than it works.

But i try to figure out why i can't use same column name in model and database in relation. For other column types (text, number...) it works. And i try to use same column names in database and in CMS model.

Any idea?

Thank you.

BG78
BG78

Hi. In your database you named it category_ID, but in your model, you named it category_id. I think this could be the problem.

1-2 of 2

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