Hi people. I am working on a project that deals with enrollment activities such as generation of subject offerings and such. I have a model called Offering which has a has_many relationship with the model Schedules. Basically, an offering has many schedules. In order to check for conflicts the room_id which is an attribute of the model Offering has to be unique along with the attributes time and days in Schedule, any suggestion on how should i do this, without using a tedious brute force approach?
Create a unique index + add a scoped validation.
Hi, thanks for the response but I would like to clarify that I have to check columns coming from two models, I am not sure how it can be implemented using validators only, but as of now i am trying a brute force approach
You can create a custom validations to do anything you need (it runs arbitrary code you place in it)
Just make sure it's efficient with proper indexes etc.
I'm not sure if I got the model perfectly but if you inherent the details.
As in , pass the
room_id and than you can run a simple
unique index on it without going through up/down relations.
Yes, you'll have an extra column (
Schedule) you might not need and can get by association , but that's not a large price for simpler design.
Join 22,346+ developers who get early access to new screencasts, articles, guides, updates, and more.