Question

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.

Was it helpful?

Solution

Ok, here is the answer:

$links = $base->ownBaseResource;

foreach($links as $l)
{
    echo $l->amount;
    echo $l->resource->name;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top