duanla3319 2010-09-27 12:45
浏览 42

用PHPcake烘焙正确的数据库命名

Just gettign into MVC developement and cakes implimentation, so I'm getting confused with table naming and id references.

I hava a table called Assets and value sotered in Assets is asset_status_id field which is meant to be a reference to the table Asset_Statuses this table is a simple list of possible statuses the assets could be in at any one time (Active, Inactive, Sold, Maintenace etc) I have chosen to use a table for this list as a) I think I'll need to add more options at some time b) I have a 'sequence' field in this table so I can control the sort order they will apear in in any drop downs.

'Cake Bake'ing seems to see a table called Asset_Statuses as an indication it exists to descibe a relations ship between the Assets table and a non-existent Statuses table. Now I know what your thinking just call the table Statues right? But I have oither 'Status' tables I'd like to use such as a Domain_Status which wont use the same status lists of course.

So what s the naming convention I should be using to make this all work easily?

  • 写回答

2条回答 默认 最新

  • dtgr6303 2010-09-27 13:47
    关注

    I am not sure that the plural of Asset Status is Asset States (you should check) and also the table need to be lower case, so asset_states, not Asset_States. But you can use a totally different table in your models. Check this. So basically create a model, name it as you like. I.e. AssetState and put:

    var $useTable = 'asset_states';
    

    and I think you won't have problems. Just be sure that in your relation belongsTo, hasMany you provide the proper class name i.e.:

    var $belongsTo = array(
       'AssetState' => array(
          'className' => 'AssetState' //Most important
       )
    );
    
    评论

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献