Print 1:many relationship in table

Notice: This thread is very old.
ydenda
Member | 21
+
0
-

Hello everyone,

I'd like to print table with my customers, where are data from two DB tables (customers/products).
I wanted to use something like
products->related('customerId')
in latte template without successvv- I am getting Call to undefined method Nette\Database\Table\Selection::related()

What is the best way I can use to print ordered products in one column for each customer in table? There can be upto 10 products for each customer ie.

desired table layout:
// id // customer_name // address // products //

thank you in advance.

petr.jirous
Member | 128
+
+2
-

Try this:

{foreach $customers as $customer}
	<tr>
		<td>{$customer->id}</td>
		<td>{$customer->name}</td>
		<td>{$customer->address}</td>
		<td>{foreach $customer->related('products') as $product}{$product->name}{sep}, {/sep}{/foreach}</td>
	</tr>
{/foreach}
ydenda
Member | 21
+
0
-

I tried, and it did the thing.

thank you.