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

Siyu Qian
Siyu Qian

Hello all,

Background:

I have an Order table which contains 'user_id' as a foreign key to defined who is the order owner or creator.
I used recorderfinder to allows the website admin to choose a user at the backend when creating an order.

The problem is the column name must be same as the relation's name: For example:
In the Model:

$belongsTo = [
     'user' => \RainLab\User\Models\User::class
];

In column.yaml:

user:
    label: User
    type: recordfinder
    list: $/rainlab/user/models/user/columns.yaml
    prompt: Click the %s button to find a user
    nameFrom: name
    descriptionFrom: email

so when I submitting the form, it is posting user instead of 'user_id', so the model does not allows me to save.

What is the best way to achieve this?

Cheers, David

Last updated

Siyu Qian
Siyu Qian

Ok. Problem Solved. The reason is that I have defined incorrect model relationships so OctoberCMS cannot pick the value correctly.

Last updated

st.james.jomuad13119
st.james.jomuad13119

You can also customize and fetch relation by using Attributes in model.

// Model: Customer
public function getFullNameAttribute()
{
        return $this->backendUser->first_name.' '.$this->backendUser->last_name;
}

Last updated

1-3 of 3

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