dongshan1959 2014-10-24 11:19
浏览 131
已采纳

我是否需要为数据库中的每个表创建单独的模型

My question is more theoritical, as I am not quite sure if it is a better way to create a model in Laravel for each table on database, if yes, what would be the benefition of it? I am using Laravel 4 Eloquent for the ORM. Thanks

  • 写回答

1条回答 默认 最新

  • dounan4479 2014-10-24 11:38
    关注

    The basic answer is yes, you should have a model for each table.

    But the long answer is "it depends". As for what "depends" is, it is something that comes with experience and also your design criteria. There is no 100% right answer that can be used everytime.

    As a principle if you plan on accessing data from tables using Eloquent, then you generally need one eloquent model per table, so you can access the table using Eloquent functions.

    As a principle you dont need a model if you never use Eloquent to access the data. i.e. perhaps you have a table that you only use the query builder on.

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

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?