質問

I have a Table called Driver and Car, Driver is allowed to have max 3 car. How is it possible to make this relation? Driver table: name, surname, Car Car table:Make, Model, Driver

役に立ちましたか?

解決

As I know the only way to get it is to overrite ValidateWrite() on the Cars table. In this method you can select count of cars by current Driver and return false if it has three or more Cars.

Something like this:

public boolean validateWrite()
{
    Cars   cars;
    ;
    select count(recid) from cars where cars.driver == this.driver;
    if(cars.recid > 3)
    {
       info('The driver can not have more than three cars');
       return false;
    }
}

Of course you need to have index on Cars.Driver to better performance.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top