redbean-嵌套豆-怎么了? [英] redbean - nested beans - what's going wrong?
问题描述
我试图获得一个简单的嵌套bean关系-我想念什么?
am trying to get a simple nested bean relationship - what am i missing?
我真的很喜欢redbean的简单ORM语法,并且真的想使用它,但是我似乎无法让它对我有用!
i really like redbean's simple ORM syntax and really want to use it, but i can't seem to get it to work for me!
还有其他类似的东西可能会更成熟吗?我想要一些轻巧,简单的工具来构建wordpress插件,但需要知道我将来可以依靠它...
Is there anything else similar to this that's a bit more mature maybe? I want something light and simple to build wordpress plugins with but need to know i can rely on it in the future...
am开始考虑仅使用ezsql/sqlite,但宁愿不使用:/
am starting to think about just using ezsql/sqlite but would rather not :/
感谢您的帮助...
function p($s){
$s = htmlentities(print_r($s,true));
echo "<pre>$s</pre>";
}
require('rb.php');
R::setup('sqlite:dbfile.sql'); //sqlite\
R::debug(true);
// R::wipe('book');
// R::wipe('author');
$book = R::dispense( 'book' );
$book->title = 'Boost development with RedBeanPHP';
$a = R::dispense('author');
$a->name = "Dave";
$book->author = $a;
list($page1,$page2) = R::dispense('page',2);
$book->pages = array($page1,$page2);
$id = R::store($book);
echo $b = R::load('book',$id);
echo $b->author->name;
尝试存储页面时出现以下错误....
I'm getting the following error when trying to store the pages....
致命错误:未捕获的异常'RedBean_Exception_Security'与 消息无效的Bean:属性页"中 /Users/sig/Sites/redbean/rb.php:1508堆栈跟踪:#0 /Users/sig/Sites/redbean/rb.php(1587): RedBean_OODB->检查(Object(RedBean_OODBBean))#1 /Users/sig/Sites/redbean/rb.php(2523): RedBean_OODB-> store(Object(RedBean_OODBBean))#2 /Users/sig/Sites/redbean/index.php(30): RedBean_Facade :: store(Object(RedBean_OODBBean))#3 {main}被抛出 /Users/sig/Sites/redbean/rb.php在第1508行
Fatal error: Uncaught exception 'RedBean_Exception_Security' with message 'Invalid Bean: property pages ' in /Users/sig/Sites/redbean/rb.php:1508 Stack trace: #0 /Users/sig/Sites/redbean/rb.php(1587): RedBean_OODB->check(Object(RedBean_OODBBean)) #1 /Users/sig/Sites/redbean/rb.php(2523): RedBean_OODB->store(Object(RedBean_OODBBean)) #2 /Users/sig/Sites/redbean/index.php(30): RedBean_Facade::store(Object(RedBean_OODBBean)) #3 {main} thrown in /Users/sig/Sites/redbean/rb.php on line 1508
推荐答案
问题在于,数组需要与其中的对象具有相同的名称,但根据关系,前缀必须是拥有的或共享的.../p>
the problem was that the array needs to have the same name as the objects in it, but with either own or shared prefixed depending on the relationship...
$book->ownPage = array($page1,$page2);
这篇关于redbean-嵌套豆-怎么了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!