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