I’m trying to get some validation setup for one of my ORM models.
I have 2 tables: parent and children. In the children table, there is a column called ‘parent’ whose value is the primary ID of a row in the parent table.
What I’m trying to do, is create a validation rule that checks the parent ID specified actually exists in the parent table.
Is there an easy way to do this?
Well I did come up with one solution. I created a static method in my Model class that accepts an ID as a parameter and just checks if the row exists.
So my Model_Child has a rules function like so:
Then my Model_Parent has the following:
This is working for me. Is there is a more elegant or proper solution?