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.

7
  • but because I'm using nested fields, I don't yet have the Product Id when I save the image id via a jquery File Upload ajax request? Commented Jan 29, 2015 at 5:16
  • Three things you can do: (1) save the parent first to get the ID, (2) have an ID generator you can call to set the ID before you save it, or (3) generate a separate (non-primary) ID to act as a surrogate key and store that in a separate field in Product (say ProductImageID). Commented Jan 29, 2015 at 16:35
  • @TMN, how could I make sure the surrogate key is unique though? Commented Jan 29, 2015 at 20:33
  • @the_ You can consider creating a product record as soon as your users enters the page. This way you have an ID nice and early. You can have a process which cleans out the DB from not finished products. Commented Jan 30, 2015 at 9:12
  • 2
    @the_: UUIDs would be better, since random number generators can (by design) produce the same number more than once. Since you're using Postgres, I'd recommend just using a sequence. Commented Feb 2, 2015 at 16:54