Many to One

33 views
Skip to first unread message

Mohamed Nazim

unread,
Oct 11, 2014, 8:04:09 AM10/11/14
to redbe...@googlegroups.com
I just started using RB.

I can't seem to find a solution to the problem.

I have two tables so far - both autogenerated in fluid mode.

user
emailverifications

The latter being a child of user. After a find an emailverification using

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

I try to get the related parent user:

$user = $verification->user;

but I am getting error "Trying to property of non-object"

I checked emailverifications table and there is a related user_id field.

What am I doing wrong?

Appreciate any help :)

Łukasz Strzyżowski

unread,
Oct 11, 2014, 11:43:18 AM10/11/14
to redbe...@googlegroups.com
Try to check if $verification is bean that is really found. Maybe its just empty.

gabor

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

Sorry for my late reply, migrating the RedBeanPHP server... :)


Use R::findOne instead of R::find.
R::find returns an array not an object ;)


Anyway,

Over here this works:


R::setup();
$user
= R::dispense('user');
$user
->name = 'Nazim';
$ev
= R::dispense('emailverification');
$ev
->code = 'ABC';
$user
->ownEmailverificationList[] = $ev;
$id
= R::store($user);

//now lets load...
$verification
= R::findOne('emailverification', ' code = ? ', ['ABC']);
echo $verification
->user;


It prints:

{"id":"1","name":"Nazim"}


cheers
Gabor

Reply all
Reply to author
Forward
0 new messages