Zend Basic Tutorial
Zend Forms
Zend Database
Zend Advanced
In real-world databases and applications, entities (tables) often need to be connected to each other.These connections are called relationships.
In Zend Framework, if you use Doctrine ORM, you define these relationships using annotations or YAML/XML config.
Imagine a blog system:
You could:
Feature |
Purpose |
---|---|
Data Integrity |
Keeps your foreign keys valid. |
Easier Queries |
Easily fetch related data with joins or lazy loading. |
Object-Oriented Access |
Work with objects instead of manual foreign key logic. |
Cascade Operations |
Save/delete related records automatically. |
Relationship Type |
Description |
Example |
---|---|---|
@OneToOne |
One entity relates to exactly one of another entity |
User ↔ Profile |
@ManyToOne |
Many entities relate to one entity |
Order → User |
@OneToMany |
One entity relates to many entities |
User → Orders |
@ManyToMany |
Many entities relate to many entities |
Users ↔ Groups |
Use Case |
Entity A |
Entity B |
Type |
---|---|---|---|
User has one Profile |
User |
Profile |
OneToOne |
Product in Category |
Product |
Category |
ManyToOne |
Blog has Comments |
Blog |
Comment |
OneToMany |
Users in Roles |
User |
Role |
ManyToMany |