简体   繁体   English

单向和双向关系关系的区别

[英]Difference between unidirectional and bidirectional relational relationship

I wonder what these two words mean. 我想知道这两个词是什么意思。

I encountered them in Doctrine's documentation , but I can't understand what they mean. 我在Doctrine的文档中遇到过它们,但我无法理解它们的含义。

This has to do with whether common usage (within the application domain) would attempt to access both sides of the relationship from the other side... Invoices to products would probably be unidirectional, as athough we often want to know what products are on an invoice, it is unlikely that you would want to know all the invoices that contain a given product. 这与通用(在应用程序域内)是否会尝试从另一方访问关系的两个方面有关...发票到产品可能是单向的,因为我们经常想知道什么产品在发票,您不太可能想知道包含给定产品的所有发票。

Stores to products on the other hand is bi-directional, as we could easily want to access both all the products at a specific store, or find all the stores that sell a specific product. 另一方面,产品的商店是双向的,因为我们很容易想要访问特定商店的所有产品,或者找到销售特定产品的所有商店。

Bi-Directional is not limited to where the relationship is a many-to-many relationship. 双向不仅限于关系是多对多关系的地方。 An employee to supervisor relationship could easily be bi-directional, if, in our domain model, an employee object will need to be able to access the employee's supervisor object, and of course, the supervisors object contains a property that lists all his assigned employees. 如果在我们的域模型中,员工对象需要能够访问员工的主管对象,那么员工与主管之间的关系可以很容易地是双向的,当然,主管对象包含列出他所有指定员工的属性。

One to Many Bidirectional: State and City, where State has collection property of Cities, and City has a State property 一对多双向:州和城市,其中州有城市的收集财产,城市有国家财产

Many to Many Unidirectional: Bus and Rider, where Bus has collection property of Riders, but Rider does not have collection property listing all Buses Rider has ridden in (application does not care). 多对多单向:公交车和公交车,其中公交车有Riders的集合属性,但Rider没有集合属性列出所有公交车骑手已经乘坐(应用程序不关心)。

Many to Many Bidirectional: Person class, where each person has Friends Property, as Collection of other person objects this person is friends with; 多对多双向:人类,每个人都有朋友财产,作为此人与朋友的其他人对象的集合;
or... 要么...
Artist and Album classes, where Artist has Albums collection, and Album has Artists Collection (where album is compilation of tracks from multiple artists) 艺术家和专辑课程,其中艺术家有专辑集合,专辑有艺术家集合(专辑是多个艺术家的曲目汇编)

Example: 例:

We have two tables in database: Student Table, Subject Table 我们在数据库中有两个表: Student表, Subject

Many-To-Many Bidirectional 多对多双向

You need apply the navigation in the database from the following two directions: 您需要从以下两个方向应用数据库中的导航:

  • Navigation from Student to Subject StudentSubject导航

A student can enroll for many subjects in the semester. 学生可以在学期注册许多科目。

  • Navigation from Subject to Student SubjectStudent导航

A Subject can have many different students enrolled for it. 主题可以有许多不同的学生注册。

Many-To-Many Unidirectional 多对多单向

You need apply the navigation in the database from the just one direction: 您需要从one方向应用数据库中的导航:

  • Navigation from Student to Subject StudentSubject导航

A student can enroll for many subjects in the semester. 学生可以在学期注册许多科目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM