Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

9
  • An interesting idea. It makes inserting a bit more complicated. I would need to check if a row already exists in FavoriteWithoutMenu first. If so, I just add a menu link - otherwise I create the FavoriteWithoutMenu row first and then link it to a menu if necessary. It also makes selecting all the favorites in one query very difficult: I'd have to do something weird like select all the menu links first, and then select all the Favorites whose IDs don't exist within the first query. I'm not sure if I like that. Commented Nov 27, 2011 at 21:40
  • I don't think inserting as more complicated. If you want to insert a record with NULL MenuId, you insert into this table. If not, to the Favorites table. But querying, yes, it will be more complicated. Commented Nov 27, 2011 at 21:43
  • Actually scratch that, selecting all favorites would just be a single LEFT join to get the menu. Hmm yea this might be the way to go.. Commented Nov 27, 2011 at 21:44
  • The INSERT becomes more complicated if you want to add the same recipe to more than one menu, since you have a UNIQUE constraint on UserId/RecipeId on FavoriteWithoutMenu. I'd need to create this row only if it didn't exist already. Commented Nov 27, 2011 at 21:48
  • 1
    Thanks! This answer deserves a +1 since it's more of a cross-database pure SQL thing.. However, in this case I'm gonna go the partial index route because it requires no changes to my schema and I like it :) Commented Nov 27, 2011 at 22:03