V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
banxi1988
V2EX  ›  程序员

关联表取个什么名字好呢?

  •  
  •   banxi1988 ·
    banxi1988 · 2013-06-08 10:35:18 +08:00 · 3916 次点击
    这是一个创建于 3981 天前的主题,其中的信息可能已经有所发展或是发生改变。
    此地址:http://en.wikipedia.org/wiki/Associative_Entities
    中的一个例子将关联表的名字取名为registers,我觉得怪怪的。
    大家觉得 student与course这种多对多关系的关联表取什么名字比较好呢?

    ------
    熟悉SQLAlchemy的看看如何写比较适合?
    class Association(Base):
    student_id = Column(Integer,ForeignKey('student.id').primary_key=True)
    subject_id = Column(Integer,ForegnKey('subject.id').priamry_key=True)
    extra_data = Column(String(50))
    course = relationship("Course")

    class Student(Base):
    id = Column(Integer,primary_key=True)
    sno = Column(String(20),unique=True)
    subject_associations = relationship("Association")

    class Course(Base):
    id = Column(Integer,priamry_key=True)
    name = Column(String(20))
    9 条回复    1970-01-01 08:00:00 +08:00
    davepkxxx
        1
    davepkxxx  
       2013-06-08 10:39:37 +08:00
    student_course
    banxi1988
        2
    banxi1988  
    OP
       2013-06-08 10:48:57 +08:00
    @davepkxxx 我一开始想到的也是这样,但是看久了,又觉得怪怪的。
    在ORM类中。取名呢?student.student_courses?
    davepkxxx
        3
    davepkxxx  
       2013-06-08 11:35:36 +08:00
    courses 或 studentCourses
    主要看有无重复字段,还有就是命名规则。
    binjoo
        4
    binjoo  
       2013-06-08 11:42:21 +08:00
    我一般就是table1_table2这样的。
    sarices
        5
    sarices  
       2013-06-08 11:49:23 +08:00
    一般是tbl12tbl2
    voidman
        6
    voidman  
       2013-06-08 12:25:15 +08:00
    student_course ,单数形式
    volCANo
        7
    volCANo  
       2013-06-08 12:51:51 +08:00
    student_course_join
    msg7086
        8
    msg7086  
       2013-06-08 13:59:38 +08:00
    student_course_taken
    darasion
        9
    darasion  
       2013-06-08 14:10:20 +08:00
    两个表的名字连一起就好了。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   816 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 22:25 · PVG 06:25 · LAX 15:25 · JFK 18:25
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.