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 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭