There are two tables with a many-to-many relation, for example:
base base_resource resource
id | name base_id | resource_id | amount id | name
----+------ ---------+-------------+------- ---+-----
1 | base1 1 | 2 | 23 1 | gold
2 | base2
Now I want to iterate all resources of one base. How can i access the property 'amount' like...
$resources = $base->sharedResource;
foreach($resources as $r)
{
echo $r->name." - ".r$->???$link???->amount;
}
?
According to redbean php
With
$base->ownBaseResource;
we only get all links from base to any resource.
Ok, here is the answer:
$links = $base->ownBaseResource;
foreach($links as $l)
{
echo $l->amount;
echo $l->resource->name;
}