Parent of Many to one throwing error

13 views
Skip to first unread message

Mohamed Nazim

unread,
Oct 11, 2014, 8:29:04 AM10/11/14
to redbe...@googlegroups.com
I started using RB only recently. In my first project, I currently have two tables:

user
emailverifications


The latter is a child of user. After I find an emailverification record using:

$verification = R::find('emailverifications','code = ?',[$code]);

$verification object is populated but when I use $verification->user I get "Trying to get property of non-object"

Both tables were generated from RB in fluid mode on an empty mysql db. Using an SQL client, I can see that emailverifications has a foreign key with user table on user_id

What am I doing wrong?

Appreciate any help... been going nuts for over two hours searching everywhere....

Thanks
rb-many-to-one.PNG

Łukasz Strzyżowski

unread,
Oct 11, 2014, 11:49:37 AM10/11/14
to redbe...@googlegroups.com
You are using find static method, that returns an array of objects co you should use:

$verification[0]->user

Or just use R::findOne method to return exactly one bean object.

Łukasz Strzyżowski

unread,
Oct 11, 2014, 11:53:58 AM10/11/14
to redbe...@googlegroups.com
Here are described all find methods: http://redbeanphp.com/api/class_red_bean_p_h_p_1_1_facade.html

In using redbean you should be careful and remember what methods return beans, array of beans or array of arrays. :)

gabor

unread,
Oct 11, 2014, 12:38:00 PM10/11/14
to redbe...@googlegroups.com

Ah I also answered in your previous message... ;)

Reply all
Reply to author
Forward
0 new messages