Is Composite Primary Key Bad For Yii?

I’m planning DB. There are 2 objects: movie (name, description) and it’s subtitles (one line is one record).

What should be the primary key in subtitles table: "movie id, subtitle id" or just "subtitle id" with table for one to many relation?




movie

  id*

  name


srt

  movie_id*

  line_id*

  txt



I prefer composite primary key, but which is better for Yii?

I don’t really see a reason to have a composite key in your subtitles table. Unless of course, you want to have something fancy like “The first subtitle line of movie 1023 is to be found at (1023, 1)”. It is debatable if that is really a good reason, though.

If you insist on using composite primary keys: Outside of linking tables, gii isn’t handling them too well. See giix for that.

Composite keys can be handled but imho should be avoided, if you can modify the database schema. That makes developing client apps much easier.

And normally composite PKs are ONLY used in join tables for MANY_MANY relations, which are not directly referenced in the application. If they are, the relation should be split into two HAS_MANY and BELONGS_TO relations and an id column should be added to the join table.