Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/244.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php redbeanppp-预加载嵌套bean_Php_Nested_Redbean - Fatal编程技术网

Php redbeanppp-预加载嵌套bean

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

我使用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;
$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
调用