redbean

How to retrieve beans using two relations on redbean


I would like to retrieve some data using one-to-many and many-to-many relations I've created bean called floor, shop, category and related them as:

floor 1:N shop
floor N:M category
shop N:M category

Now i want to retrive all shops given category and floor ids Here is my code

$floor = R::load('floor',$f_id);
$category = R::load('category',$cat_id);
$shops= $floor->via('category')->withCondition('id = ?',[$category ->id])->ownShopList;
var_dump($shops);

But $data is empty array. I'm shure i've related beans correctly. What am I doing wrong please help! Maybe there is another way to retrieve them i'll appreciate any solution. Thanks!


Solution

  • $category = R::load('category',$cat_id);
    $shops= $category->withCondition('floor_id = ?',[$f_id])
                     ->sharedShopList;