zoukankan      html  css  js  c++  java
  • SpeedPHP关于一对一和一对多关联关系的建立 model建立

    新闻表:t_news

    新闻类型表:b_type_to_name

    其中一个新闻类型可以包含多个新闻(hasmany),一个新闻只能属于一种新闻类型(hasone)

    下面是新闻model类:

    <?php
    
    /**
     * 新闻
     * @author HYY
     *
     */
    class m_news extends spModel {
        var $pk = "id"; // 每个留言唯一的标志,可以称为主键
        var $table = "t_news"; // 数据表的名称
        
        var $linker = array(
                array(
                        'type' => 'hasone',   // 一对多关联
                        'map' => 'typeToName',    // 关联的标识
                        'mapkey' => 'type_id',// 本表与对应表关联的字段名(意义:拿本表的哪个字段与另外一个表关联)
                        'fclass' => 'm_typeToName',// 对应表的类名
                        'fkey' => 'typeId', // 对应表中关联的字段名(意义:另外一个表的字段)
                        'enabled' => true // 启用关联
                )
        );
    }
    
    ?>

    这个是新闻类型类:

    <?php
    
    /**
     * 新闻类型
     * @author HYY
     *
     */
    class m_typeToName extends spModel{
        var $pk = "typeId"; // 每个留言唯一的标志,可以称为主键
        var $table = "b_type_to_name"; // 数据表的名称
        
        var $linker = array(
                array(
                        'type' => 'hasmany',   // 一对多关联
                        'map' => 'newsSet',    // 关联的标识
                        'mapkey' => 'typeId',// 本表与对应表关联的字段名
                        'fclass' => 'm_news',// 对应表的类名
                        'fkey' => 'type_id', // 对应表中关联的字段名
                        'enabled' => true // 启用关联
                )
        );
    }
    
    ?>
  • 相关阅读:
    jdbc调用存储过程和存储函数
    jdbc测试
    JDBC -JSP
    eclipse连数据库(sql server)的注意事项
    九大内置对象(新)
    application 全局对象
    编码:session
    建库和建表
    db vs dbm
    Source Insight异常退出,错误代码C0000005
  • 原文地址:https://www.cnblogs.com/wuyou/p/3495345.html
Copyright © 2011-2022 走看看