KoolReport's Forum

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

Some questions about relations setup #3112

Open Eugene opened this topic on on Jul 30, 2023 - 3 comments

Eugene commented on Jul 30, 2023

Hi, I am sorry for so many questions but some points in the documentation are unclear for me.

  1. In your documentations for BelongsTo you provide an examle for Order class. But in your demo you don't use this method for Order class. So – my questions are - why don't you use it and when should I use it?

  2. Let's for exanmple I have a table Foo that has relattions with the table Users (Foo has foreign key referred to primary key of the table UsersFoo.user_id ->Users.id). I don't need to show or edit or manage any way the table Users in my application - just want to have possibility to select Users for my table Foo. Do I have to create the Resource class for table Users in this case.

  3. You use the method query in your realisztion of the Order class. I did not find any description for this method in the documentation for Resource. Could you explain the usage of the method query in more details in Resource context?

KoolReport commented on Jul 31, 2023

Hi Eugene,

For your questions:

  1. It can be used there, if you use then in the detail page for Order, you will see a section to list relationship with Customer. There will be one customer only. For demo purpose, we use HasMany so that 1 order will show list of OrderDetail rows.
  2. You don't need. You only need to change the query().
  3. Now here is when query() method come in. By default, the query() will return the columns in a table only like in Order table. But, what if we need the join with Customer to get CustomerName then you can alternate the query to get the extra information.
Eugene commented on Aug 1, 2023

Thanks but why do you use so many separate 'select' in your query?

$query->leftJoin("customers","orders.customerNumber","=","customers.customerNumber")
            ->select("orderNumber","orderDate","shippedDate","status")
            ->select("customerName")
            ->select("orders.customerNumber");

What SQL query is it equal to?

KoolReport commented on Aug 1, 2023

You can write:

->select("orderNumber","orderDate","shippedDate","status")

or

->select("orderNumber")
->select("orderDate")
->select("status")

is the same thing. We design this way so in the case you have list of columns, you can do this easier:

foreach($columnNames as $cName)
{
    $query->select($cName);
}

it will be faster.

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
help needed

Dashboard