KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Relation: How to display a field form relation table? #2634

Closed Peter Wendel opened this topic on on Apr 7, 2022 - 5 comments

Peter Wendel commented on Apr 7, 2022

Hi again!

I have a problem using relations and I cannot solve by reading documentation or demo-code either:

I want show a field from the related table that is not an ID-field.

So here is the created resource:

<?php

namespace App\KV\Dashboard\Resource;

use App\KV\Dashboard\DataSources\Data;
use App\KV\Dashboard\Glasses\HmFgKtfgDefAllQ;
use App\KV\Dashboard\Inputs\HmFgKtfgCopyUpButton;
use koolreport\dashboard\containers\Html;
use koolreport\dashboard\containers\Modal;
use koolreport\dashboard\containers\Panel;
use koolreport\dashboard\containers\Row;
use koolreport\dashboard\fields\RelationLink;
use koolreport\dashboard\inputs\Button;
use koolreport\dashboard\fields\ID;
use koolreport\dashboard\admin\relations\BelongsTo;

class HmFgKtfgDef extends \koolreport\dashboard\admin\Resource
{
    protected function onCreated()
    {
        $this
            ->manageTable("def_fg_quartal")
            ->inSource(Data::class)
            ->listScreen()
            ->adminTable()
            ->pageSize(20)
        ;
    }



    protected function relations()
    {
        return [
            BelongsTo::resource(AvdDefFg::class)->link(['fg' => 'fg'])->title('fg-Name'),
        ];
    }

    protected function fields()
    {
        return [
            ID::create('kv_quartal')->label('KV-Quartal')->showOnUpdate(true),
            ID::create('ktfg')->label('Kostenträger-FG')->showOnUpdate(true),
            ID::create('fg')->label('Fachgruppen-ID')->showOnUpdate(true),
            RelationLink::create('fg')->label('Fachgruppen-Name')
                        ->formatUsing(function($value,$row){ return $row['fg']; })
                        ->linkTo(AvdDefFg::class)
        ];
    }

    protected function highlights()
    {
        return [
            Panel::create()->header('<h4>Tools</h4>')->type('primary')->sub([
                Row::create()->sub([
                    Html::h5('Quartalskonfiguration übertragen.'),
                    Html::p('Die FG/KTFG-Konfiguration wird damit automatisiert z.B. von 20204 nach 20211 übertragen.
                    Veränderte Werte können dann dort editiert werden. Die benötigten Werte ermittelt das System selbst.'),
                    Button::create()->text('Quartalskonfiguration übertragen')->onClick(function(){ return Modal::show('QEingabe');})
                ]),
                Modal::create('QEingabe')->sub([
                    Html::h5('Bist du sicher, dass du diese Operation jetzt ausführen möchtest?'),
                    Html::hr(),
                    HmFgKtfgCopyUpButton::create()->onClick(function(){
                        return Modal::hide("QEingabe");
                    }),
                ])->title('Quartale auswählen')->showCloseIcon(true)->size("md")->open(false)->animation('fade')
            ])
            ];
    }

    protected function glasses()
    {
        return [
           HmFgKtfgDefAllQ::create()
        ];
    }
}

And here is the related resource:

<?php

namespace App\KV\Dashboard\Resource;

use App\KV\Dashboard\DataSources\Data;
use koolreport\dashboard\admin\relations\HasMany;
use koolreport\dashboard\fields\ID;
use koolreport\dashboard\fields\Text;

class AvdDefFg extends \koolreport\dashboard\admin\Resource
{
    protected function onCreated()
    {
        $this
            ->manageTable("def_fg")
            ->inSource(Data::class)
            ->listScreen()
            ->adminTable()
            ->pageSize(20)
        ;
    }

    protected function relations(){
        return [
            HasMany::resource(HmFgKtfgDef::class)->link(['fg' => 'fg'])->title('Fachgruppen-Name')
        ];
    }

    protected function fields(){
        return [
            ID::create('fg')->label('FG-ID'),
            ID::create('text')->label('Fachgruppen-Name lang'),
            Text::create('web_text')->label('Fachgruppen-Name Web'),
            Text::create('abk')->label('Fachgruppe-Abkürzung')
        ];
    }
}


The thing I want to do is to display the field 'text' related to the field 'fg'.

I think I made something wrong with the relation or you use relations an other way as I think from the databse way...

Can you help me?

Regards, Peter

KoolReport commented on Apr 8, 2022

Currently the Resource only support 1 ID per table, it seems to me you have multiple ids, is it correct?

Peter Wendel commented on Apr 8, 2022

Yes, there is more than 1 ID according to table index.
So if i have only one, how does it work then? Main ID is 'fg'.

I will override updtaeRecord() then to pass through the tables indices correctly.

KoolReport commented on Apr 8, 2022

If the main id is "fg" then only "fg" field, you use ID for it. May I know more details on what you would like to complete.

Peter Wendel commented on Apr 8, 2022

Okay, I 'll show this in SQL:

select a.kv_quartal, a.kftg, a.fg, b.text from def_fg_quartal a join def_fg b on b.fg = a.fg;
Peter Wendel commented on Apr 8, 2022

Meanwhile we discussed the usage of Dashboard/AdminPanel for our Project in our team and came to the decision to cancel it.

Your tool seems to be fine, when only easy data operationd (such as custome/order things) must be done, but we need more complex operations for working with our, most with multiple indices fitted, tables without a ID-field as you need to process. Another point is our data spreading over more than one database on the server and mostly nedeed to be combined with joins to build the data view that is needed.

So Dashboard/AdminPanel seems not to be the tool fitting our needs. Maybe a later version will be better for us.

Thanks for your friendly help so far!

Regards, Peter

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
solved

Dashboard