Problem with shared-lists when referencing the same bean type

48 views
Skip to first unread message

Marko Tukiainen

unread,
Feb 5, 2016, 5:38:37 AM2/5/16
to redbeanphp
Hello,

It's been a while since I've posted but I've been happily using RedBeanPHP without many issues. However now I've come across a problem that I can't seem to be able to fix myself. I'm using the version 3.5.13.

I have product beans that need to have a reference to other product beans. I've used sharedProduct for this, and it has seemed to work fine. As expected, the link table is called 'product_product' in this case. 

Now I ran into a situation where I need to add a qualifier for this relationship. When trying this, I was unable to access the link beans with the ownProductProduct syntax. So I figured I'd use a different link table name to see if it helps. 

I tried creating the relations with $product->via('linkedproduct', array(type => $type))->product but this didn't seem to create a proper table. Changing it to $product->via('linkedproduct', array(type => $type))->linkedproduct works. 

However with the latter version I am unable to fetch the actual linked products. I can load the link beans just fine, but I can't get a list of the shared linked products - I guess this due to the fact that RedBeanPHP doesn't know which table to use to resolve the linkedproduct_id in the link table. 

There are a bunch of alias, fetchAs, etc. functions but I haven't been able to find a combination that would resolve this. 

Help?


gabor de mooij

unread,
Feb 6, 2016, 6:00:24 PM2/6/16
to redbe...@googlegroups.com
I will take a look at this asap.

--
You received this message because you are subscribed to the Google Groups "redbeanphp" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redbeanorm+...@googlegroups.com.
To post to this group, send email to redbe...@googlegroups.com.
Visit this group at https://groups.google.com/group/redbeanorm.
For more options, visit https://groups.google.com/d/optout.

gabor

unread,
Feb 7, 2016, 6:39:40 AM2/7/16
to redbeanphp

Easiest way is to create a view, for instance productinfo and rename the columns in such a way you can easily target them with RB and with custom SQL.

cheers
Gabor

Marko Tukiainen

unread,
Feb 8, 2016, 3:31:45 AM2/8/16
to redbeanphp
I ended up with not making any views and just using a custom query with convertToBeans, like so:

$product->sharedProduct = $this->db->convertToBeans('product', $this->db->getAll('select product.* from product left join linkedproduct on (product.id = linkedproduct.linkedproduct_id) where linkedproduct.product_id = :id', array(':id' => $product->id)));

Marko 
Reply all
Reply to author
Forward
0 new messages