2

在我的新项目中,我决定将RedBean ORM系统与CodeIgniter PHP Framework一起使用。

如何从具有简单关系的表中获取所有记录?我知道我可以使用R::execor R::getAll查询,但我想确定是否有其他解决方案。

表结构:

语言

  • ID
  • 标题

类别

  • ID
  • 语言标识
  • 标题

表中的字段language_id与表中的字段categories相关。idlanguages

我的目标:

SELECT l.title, c.* 
FROM categories AS c 
LEFT JOIN languages AS l 
    ON (c.language_id = l.id)

有什么解决办法吗?

4

1 回答 1

1
list($language1, $language2, $language3) = R::dispense('language', 3);
$language1->title = "PHP";
$language2->title = "Python";
$language3->title = "Ruby";

list($category1, $category2, $category3) = R::dispense('category', 3);
$category1->title = "CodeIgniter";
$category2->title = "Django";
$category3->title = "Rails";


R::store($language1);R::store($language2);R::store($language3);
R::store($category1);R::store($category2);R::store($category3);


$category1->language = $language1;
$category2->language = $language2;
$category2->language = $language3;


R::store($category1);R::store($category2);R::store($category3);

$categories = $language1->ownCategory;
于 2011-11-10T18:41:22.640 回答