Validation of a value

Hi! In my project I need to make a Car's Location Service. So, I need to link a Car to only one Driver, at the same time I can link a Driver to more than one car. Where and how can I validade this information? And how can I make a time line field to register all the previous registrations instead of just refreshing the info?

mvp_badge
MVP

Hell there Eduarda,

Hope you're doing well.

So according to your description, you have 2 concepts: Car and Driver. As such, these will be entities in your application.


"So, I need to link a Car to only one Driver, at the same time I can link a Driver to more than one car."

If you want to do this, you need to have a DriverId attribute in Car entity.

This will lead that one Car can only have one Driver, but the same Driver can be associated to several Cars.


If you want to make a timeline to hold all the previous registrations, there are several ways to do that. You can have flags in your entities that refer to old records. Or you can store this old information in another entity / entities.


Hope that this helps you!


Kind regards,

Rui Barradas

Hi Eduarda,

I think your first step is to create a good datamodel, that matches with both your information needs and your business rules.

You would probably have a car, a driver and a location as some of your entities.

The location will do all the heavy lifting, it would probably have a begin and end date and time.  And most likely some sort of status information (requested / planned / car ready / car retrieved / car returned / closed ...)

The location would be a junction table between driver and car.  Each location is for exactly one car and one driver, but a driver can be part of many locations, and a car can be part of many locations.

So your business rule about only one location for a car at a time, is not covered by the datamodel.  You'll have to write code to check for overlap on the dates, typically in the entity action wrapper of location entity.

As for your information need of a timeline, that is the location records attached to a given car sorted by date.

Hope this gets you started in the right direction,

Dorine

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.