I have Shop has_many documents.
I do not want create a Shop without almost one document associated.
That is: now I can do shop=Shop.create(…) and shop.documents is
[], instead I don’t want the possibility to create a shop without
almost one document.
How can I do this?
Msan M. wrote in post #1007398:
I have Shop has_many documents.
I do not want create a Shop without almost one document associated.
That is: now I can do shop=Shop.create(…) and shop.documents is
[], instead I don’t want the possibility to create a shop without
almost one document.
How can I do this?
I haven’t actually tried this myself, but according to this validates
:presence in Rails 3 will do what you want:
http://jeppe.liisberg.dk/2011/02/03/validate-presence-of-at-least-one-associated-record/