Results 1 to 5 of 5
Feb 10, 2006, 17:11 #1
- Join Date
- May 2002
- 0 Post(s)
- 0 Thread(s)
Lifecycle of HABTM related models
I have the following models
SupportedOperatingSystem [intersection entity]
An Installer can have many OperatingSystems, the operating systems that it supports are maintained in SupportedOperatingSystem model. It is required that and Installer be associated with at least 1 OperatingSystem.
validation code in Installer model
def validate if self.operating_systems.empty? errors.add_to_base('You must select at least one Operating System') end end
[x]os1 [ ]os2 [ ]os3
os1 is checked because when I created the Installer model I associated it with os1. So now I uncheck os1 and click "update." I get an error message as expected "You must select at least one Operating System." But, if I check the "supported_operating_systems" table, this association has been deleted, even though the validation failed. This is bad, because if the user decides to close their browser then the Installer model will be left in an invalid state. Is there a way to prevent this? Why is the record being deleted even though validation does not succeed?