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

that0n3guy
that0n3guy

I'm using the relation formwidget in a model form like so:

fields:
    code:
        label: Code
    institutions:
        label: Institutions
        type: relation

The institution database looks like so:

        $table->increments('id');
        $table->string('title');
        $table->string('slug');
        $table->text('body');

I always get this error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'name' in 'field list' (SQL: select `name`, `id` from `that0n3guy_diqs_institutions`)

The error makes sense because I don't have a name column. I realize that I could just rename my title column to name... but that's not the point so please don't suggest this.

How do I set the name column (see: https://github.com/octobercms/october/blob/master/modules/backend/formwidgets/Relation.php#L59) when using the relation formwidget?

Last updated

that0n3guy
that0n3guy

I tried to set this in the yaml file a bunch of different ways... no go... here are somethings I tried none work

institutions:
    label: Institutions
    type: relation
    config:
        nameColumn: title

or

institutions:
    label: Institutions
    type: relation
    nameColumn: title

or

institutions:
    label: Institutions
    type: relation
    namecolumn: title

or

institutions:
    label: Institutions
    type: relation
    name: title

Last updated

that0n3guy
that0n3guy

I figured it out!

fields:
    name:
        label: Code
    institutions:
        label: Institutions
        type: relation
        options:
            nameColumn: title

You set it under options.

Utility
Utility

Works for me as well! Thanks!

maxDubovsky
maxDubovsky

It's not working for me for the HasMany relation ...

cydrick.nonog
cydrick.nonog

for hasmany.. this will not work... beacause it is many relationship. because you i can make look up for the record that you want to fetch...

to do this with your hasmany you must specify also the index

example: account has many transactions. for the configuration you need to di this

transaction[1][title]: label: 1st transaction

1-6 of 6

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