Assuming I have the following DB model:
Car(
id INT
plaque_id INT
)
Plaque(
id INT
identification TEXT
)
So in ActiveJDBC, my models are:
public class Car extends Model {
static{
validatePresenceOf("plaque_id");
}
public Car () {}
}
..
public class Plaque extends Model {
static{
validatePresenceOf("identification");
}
public Car () {}
}
Assuming my specification says: a car must have a plaque.
As you can see, I am enforcing the presence of plaque_id to the Car model.
Now. When I try this:
Car model_s = new Car();
Plaque plaque_a = new Plaque();
plaque_a.set("identification","A-8000");
plaque_a.saveIt();
car.add(plaque_a);
car.saveIt();
I got the following exception thrown:
java.lang.IllegalArgumentException: You can only add associated model to an instance that exists in DB. Save this instance first, then you will be able to add dependencies to it.
If I understand correctly, my car model_s must be saved first before being able to link plaque plaque_a. But I cannot save model_s without a plaque due to my validation rule. It's a catch-22.
Note: I am new to activeJDBC.