• 请不要在回答技术问题时复制粘贴 AI 生成的内容
banxi1988
V2EX  ›  程序员

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

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