views:

51

answers:

1

Hey,

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. However 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!

+1  A: 

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
prodigitalson
Interesting. but that creates one large table with all of the columns. this doesn't sound like a great idea if I want to add more subclass tables in the future.
Daniel Hertz
Concrete inheritance (as opposed to Column Aggregation) will put them in separate tables. Although using a migration would allow you to add columns at a later date.
prodigitalson
Thanks again for your help. So I tried the concrete, but it doesnt seem to actually add any rows into the media table. The whole point of why I want to do this is to keep the id's synced between all of the media types so that I can attach comments and tags to all of them.Any ideas?Thanks!
Daniel Hertz