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

Tschallacka
Tschallacka

When you have a relationship defined in your Model and try to access it in your controller as follows

columns.yaml

columns:
    hotel_webname:
        label: exitcontrol.hotelmanager::lang.hotelmanagermodel.hotel_webname

hotel:
        label: exitcontrol.hotelmanager::lang.hotelmanagermodel.hotel_name

Model.php

public $belongsTo = ['countries' => [
        'ExitControl\CountryManager\Models\CountryModel',
    ],
    'hotel' => [
            'ExitControl\HotelManager\Models\HotelManagerModel',
    ],
];

You might notice you're getting a lot of json 'garbage'

json garbage

If you wish to filter this out in neat columns you do not need to set up multiple specific relation ships. You can just use the one relationship over and over again in columns.yaml to define the fields you wish to display. You just need to specificy which colums to display from the relation ship defined in the model.

In my model the name of the relationship is 'hotel'. In the JSON garbage we can see which fieldnames are actually supplied to us(usually this will match the database table names, but the JSON is the definite guide of what's supplied to you)

If we change in columns.yaml the hotel: for the following lines, we can get the 3 lines we want from the relationship and reuse the same defined relationship over and over:

hoteldisplay:
    relation: hotel
    valueFrom: hotel_name
    label: Hotel Name

hotelcode:
    relation: hotel
    valueFrom: hotel_code
    label: Hotel Code

hotelnewcode:
    relation: hotel
    valueFrom: hotel_newcode
    label: Hotel New code

now we have 3 columns for the price of one.

Last updated

1-1 of 1

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