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

wilirius15434
wilirius15434

Problem

I have a belongsTo/hasMany relationship between two models, Course and CourseInstance. CourseInstance includes a record finder to match the CourseInstance with a Course. The problem is that whenever I click on the record finder in the backend I get an error. "CourseInstance Model does not contain a definition for 'course_id'."

Yet you can see course_id is clearly defined:

class CourseInstance extends Model
{
    public $belongsTo = [
        'course' => ['Mandr\Vct\Models\Course'],
    ];
}

And then in the fields.yaml file I have:

fields:
    course_id:
        label: 'Course'
        span: auto
        type: recordfinder
        list: $/author/plugin/models/course/columns.yaml
        prompt: Click the %s to find a course
        nameFrom: course_number

Solution

The issue is that field names in the fields.yaml file should be relations, not field keys. So in fields.yaml, instead of having 'course_id', it should just be 'course':

fields:
    course:
        label: 'Course'
        span: auto
        type: recordfinder
        list: $/author/plugin/models/course/columns.yaml
        prompt: Click the %s to find a course
        nameFrom: course_number

Thanks to spunky for that one.

Last updated

arbitrobk18211
arbitrobk18211

I have two relations (type: belongsto) and i place two fields (recordfinder) in my configuration file (fields.yaml). When i do a double click to the second of them it returns the list of the first of them. Is it possible to insert a multiple of recordfinder in a form? Thanks

Last updated

1-2 of 2

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