dongzangchui2072 2012-12-08 13:11
浏览 41
已采纳

为什么RedBean没有使用多个表名?

Or can we do that? It's doesn't look good too when you say:

$book = R::dispense('books');

and just handle the naming with an RedBean_IModelFormatter or am I missing something? Thanks.

  • 写回答

1条回答 默认 最新

  • duanbigan7765 2012-12-08 16:22
    关注

    You can do it, but it gets confusing and doesn't look good. The standard convention is non-plural table names to make more sense when dispensing a book and storing a book, as well as with relation mapping. Imagine if you will the following:

    $book=R::dispense('books');
    $book->title='War and Peace';
    $pageOne=R::dispense('pages');
    $pageOne->number=1;
    $pageTwo=R::dispense('pages');
    $pageTwo->number=2;
    $book->ownPages=array($pageOne,$pageTwo);
    R::store($book);
    

    That looks fine. Now lets say we load a page and go to fetch the associated book:

    $page=R::load('pages',1);
    echo $page->books->title;
    

    This doesn't make as much sense and doesn't quite fit what RedBean is after. Again, you can do it. If you have a database already set up, you may not want to make those changes. Again, it is all your decision and what you are trying to accomplish. If it is just you, then do whatever. If you are working in a group, it might make more sense to rename the tables so that your work is more legible.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?