Php redbeanppp-预加载嵌套bean
我使用redbeanhp。假设我有以下结构:Php redbeanppp-预加载嵌套bean,php,nested,redbean,Php,Nested,Redbean,我使用redbeanhp。假设我有以下结构: <?php require_once 'redbean/RedBean/redbean.inc.php'; R::setup('sqlite:test.sqlite'); $user = R::dispense('user', 1); $user->name = 'john'; R::store($user); $post = R::dispense('post', 1); $post->author = $user; $po
<?php
require_once 'redbean/RedBean/redbean.inc.php';
R::setup('sqlite:test.sqlite');
$user = R::dispense('user', 1);
$user->name = 'john';
R::store($user);
$post = R::dispense('post', 1);
$post->author = $user;
$post->text = 'great post';
R::store($post);
$comment = R::dispense('comment', 1);
$comment->post = $post;
$comment->author = $user;
$comment->text = 'great comment';
R::store($comment);
我的问题是,它打印出如下内容:
$post = R::load('post', 1);
R::preload($post,
[
'author' => 'user', //this makes $post->author->name work
'comment',
//what I've tried in order to get $post->comments[...]->author->name to work:
//'comment.author',
//'comment.author' => 'comment.user',
//'comment.author' => 'user',
//'author' => 'comment.user',
]);
echo 'post author: ' . $post->author->name
. PHP_EOL;
foreach ($post->ownComment as $comment)
{
echo 'comment: ' . $comment->text
. ' by ' . $comment->author->name
. PHP_EOL;
}
post author: john
comment: great comment by
如您所见,没有关于评论作者的信息。除了手动获取注释/作者之外,我还能做什么呢?终于让它开始工作了:我必须将
'owncoment.author'=>'user'
附加到R::preload
调用