如何访问依赖于两个表/表条目的链接 Bean


How to access the link bean dependent on both tables/table entries?

有两个具有多对多关系的表,例如:

base               base_resource                       resource
id  |  name         base_id  | resource_id | amount     id | name
----+------         ---------+-------------+-------     ---+-----
 1  |  base1          1      |  2          | 23          1 | gold
 2  |  base2

现在我想迭代一个基础的所有资源。我如何访问属性"金额",例如...

$resources = $base->sharedResource;
foreach($resources as $r)
{
   echo $r->name." - ".r$->???$link???->amount;
}

根据红豆php

$base->ownBaseResource;

我们只获取从基础到任何资源的所有链接。

好的,这是答案:

$links = $base->ownBaseResource;
foreach($links as $l)
{
    echo $l->amount;
    echo $l->resource->name;
}