1
RedBeanPHP를 사용합니다. 나는 구조 다음 있다고 가정RedBeanPHP - 중첩 된 bean 사전로드
<?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);
가 지금은 수동으로로드하지 않고 모든 코멘트 저자를 검색 할 (. 즉, 나는 R::find('comment', 'post_id = ?', [1])
과 같은 코드를 피하기 위해 싶습니다). 나는 이런 식으로 작업을 수행합니다
$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
은, 주석 저자에 대한 정보가 없습니다. 주석/작성자를 수동으로 가져 오는 것을 제외하고는 어떻게해야합니까?