Getting children with findOne

39 views
Skip to first unread message

Kjetil Aleksander Aasen Haaheim

unread,
Sep 5, 2017, 9:31:31 AM9/5/17
to redbeanphp
Hi there!

I have been using RedBeanPHP for a while, and I must say it is absolutely brilliant! Thank you for the work and effort you have put into this ORM.

I have different tables linked by a one-to-many relationship, and when I execute R::findAll('schema'), it includes referenced children (ownXXXX). However, when I use R::findOne (or R::load with ID for that matter) to just find one specific entry, the linked data is not provided. It might just be a misunderstanding on my part, is this expected behaviour? Is there another way to find one bean, including own-properties?

Thank you for any tips or info you might be able to provide.

Kind regards,
Kjetil Haaheim.

gabor

unread,
Sep 5, 2017, 4:13:39 PM9/5/17
to redbeanphp


Hi,

The simplest way is to use the ownProperties, that's the way to do it in RedBeanPHP.
That being said, if you're optimizing for performance you could use:

https://redbeanphp.com/index.php?p=/finding#find_multi

but that's a fairly complex method.

If it's for debugging, just use R::exportAll(), if it's just a plain list and you don't need any beans at all (just display) why not an old-fashioned query?

It totally depends on context....

cheers,
Gabor

Kjetil Aleksander Aasen Haaheim

unread,
Sep 6, 2017, 2:33:13 AM9/6/17
to redbeanphp
Greetings again from Norway, 

Thank you for your quick response! I am using the ownProperties, as I am not concerned about performance on this project. I am exporting it through exportAll() or $bean->export(), but as mentioned it will only load the ownProperties when using findAll instead of findOne/load.

I have associated the data exclusively with xown:



REQUEST When using

, after exportAll I get the following data:

DATA:


REQUEST When using findOne:

, proceeded by $data->export(), I do not get ownProperties:

DATA:


UPDATE: as I was writing this, I changed $bean->export(), to R::exportAll($bean), which did resolve the issue for me. It was just a matter of syntax in my case, I apologise for the misunderstanding on my part. Instead of removing all info above, I am including my sample data as perhaps someone else might learn something from this.


Thank you for your work Gabor! Is it possible to donate to you in any way, except for buying RED-1 support?


Kind regards,

Kjetil Haaheim 

gabor

unread,
Sep 6, 2017, 3:26:18 PM9/6/17
to redbeanphp

sure, I re-activated the donation page ( I assumed people did not donate anymore these days and want something in return, but alas... )

https://redbeanphp.com/index.php?p=/donate



On Tuesday, September 5, 2017 at 3:31:31 PM UTC+2, Kjetil Aleksander Aasen Haaheim wrote:
Reply all
Reply to author
Forward
0 new messages