سؤال

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