开发者

Symfony is-a database schema

开发者 https://www.devze.com 2022-12-15 08:54 出处:网络
So I am new to symfony and am trying to make a is-a relationship between several tables. I have a media table that has a id field that is the primary key. I then except to have 2 or more additional ta

So I am new to symfony and am trying to make a is-a relationship between several tables. I have a media table that has a id field that is the primary key. I then except to have 2 or more additional tables that are "subclasses" of this table such as an article or event table. These are subclasses of the media table and I put a media_id field in these tables that have FK constraints with the media table and are primary keys of the specific tables. Ho开发者_如何转开发wever when I build the module based off of this model, this relationship does not hold.

For example, when I try adding an article, I have to add a media item first, but then in the create article form, there is no way to add a media id to it.

Any ideas?

Thanks!


Use inheritance instead of a relationship:

detect_relations: true
Media:
  columns:
  #columns for all sub classes

Event:
 columns:
 # other columns for Event Subclass
 inheritance:
    extends: Media
    type: column_aggregation
    key_field: type
    key_value: 1

Other:
 columns:
 # other columns for Other Subclass
 inheritance:
    extends: Media
    type: column_aggregation
    key_field: type
    key_value: 2
0

精彩评论

暂无评论...
验证码 换一张
取 消