Association Table Mappings Association Table Mapping

Source: Internet
Author: User

Save the Association as a table and store the foreign key of the associated table

  • In an object, a collection is used as a domain value to handle multiple domains.
  • In db, there can be only a single domain value.
  • The core of the foreign key mapping is the use of foreign keys to maintain contact on the single-valued side of the association relationship.
  • In many-to-many relationships, there is no single-valued end.
  • Operating mechanism
  • Use a linked table to save the association relationship.
  • There are only two fields, that is, the foreign key IDs of the two associated tables.
  • For each pair of associated objects, it will have a row of data corresponding to it.
  • The linked table does not have a corresponding memory object. So there is no ID. Its primary key is a combination of two primary keys for the associated table.
    • Loading data from a linked table requires two queries, such as the problem of loading a function for an employee
      • 1, Query the Employeesskills table and draw all the rows that the employee is associated with.
      • 2, based on the ID of these associated rows, find out all the function objects.
      • When this information already exists in memory, there is no problem. Otherwise, the DB query overhead is required multiple times.
  • Use time
    • The standard situation is a many-to-many association relationship.
    • When the associated table structure cannot be changed, it can only be used.
    • Sometimes the associated table stores information about a relationship, and it corresponds to a real domain object.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.