Cakephp: Designpattern for creation of models in hasMany relationship

Posted by Chris on Stack Overflow See other posts from Stack Overflow or by Chris
Published on 2010-12-24T13:34:18Z Indexed on 2010/12/24 13:53 UTC
Read the original article Hit count: 168

Filed under:

I have two Models: Car and Passenger.

Car hasMany Passenger

Passenger belongsTo Car

I managed to create add functionailty for each model and managed to resolve the hasMany relationship between them.

Now I'm trying to create a addCar function and view that allows the user to create a new car and automatically generate Passengers.

I thought of something like this

  • The view asks the user enter the car information
  • The view has some field that allows to temporarly add new passengers and remove remove them
  • When the user saves the new car, the entities for the passengers are created, the entity for the car is created and the passengers are linked to the car.
  • If the user decides to cacnel everything, the DB remains unchanged.

Now my question is: What is the best way to do this? Is there a pattern / tutorial to follow for such a entity and associated subentity creation?

To clarify: The passengers associated with each car do not exist prior to the existence of the car.

© Stack Overflow or respective owner

Related posts about cakephp