Load a bean and relations

40 views
Skip to first unread message

Renan Takeshi

unread,
Sep 5, 2014, 9:09:12 AM9/5/14
to redbe...@googlegroups.com
Hi, 
I'm starting at RedbeanPHP and I'm having this situation.

I created a bean named $user.
My user can get a lot of $skills.

So my code is something like this:

$user  = R::dispense('user');
$user->name = "user name";

$skill = R::dispense('skill');
$skill->name = 'skill name';

$user->ownSkillsList[] = $skill;

$id = R::store($user);

Until this moment, everything is ok.

When I tried to load: $user = R::load('user', $id);

My list isn't at $user.

I tried to do something like that:

$user->ownSkillsList = R::findAll('userskills', ' user_id = ? ', [ $user->id ] );

My list becomes OK, but when I'm receiving at my javascript like a json object, the list cames only with the Plain Object, with the respective id.

What am I doing wrong?

Thanks a lot.

daslicht

unread,
Sep 6, 2014, 1:27:46 PM9/6/14
to redbe...@googlegroups.com
Have you tried something like :

$user = R::load('user', $id);
foreach ($user->ownSkillsList as $key => $value) {
   ...
}

?
Reply all
Reply to author
Forward
0 new messages