V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
banxi1988
V2EX  ›  程序员

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

  •  
  •   banxi1988 ·
    banxi1988 · Jun 8, 2013 · 4471 views
    This topic created in 4712 days ago, the information mentioned may be changed or developed.
    此地址: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 replies    1970-01-01 08:00:00 +08:00
    davepkxxx
        1
    davepkxxx  
       Jun 8, 2013
    student_course
    banxi1988
        2
    banxi1988  
    OP
       Jun 8, 2013
    @davepkxxx 我一开始想到的也是这样,但是看久了,又觉得怪怪的。
    在ORM类中。取名呢?student.student_courses?
    davepkxxx
        3
    davepkxxx  
       Jun 8, 2013
    courses 或 studentCourses
    主要看有无重复字段,还有就是命名规则。
    binjoo
        4
    binjoo  
       Jun 8, 2013
    我一般就是table1_table2这样的。
    sarices
        5
    sarices  
       Jun 8, 2013
    一般是tbl12tbl2
    voidman
        6
    voidman  
       Jun 8, 2013
    student_course ,单数形式
    volCANo
        7
    volCANo  
       Jun 8, 2013
    student_course_join
    msg7086
        8
    msg7086  
       Jun 8, 2013
    student_course_taken
    darasion
        9
    darasion  
       Jun 8, 2013
    两个表的名字连一起就好了。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2343 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 04:40 · PVG 12:40 · LAX 21:40 · JFK 00:40
    ♥ Do have faith in what you're doing.