+1 for your version 2 (Fat Model). It is the way I do things for similar cases.
Sometimes you want to do it beforeSave (this model should be saved only if the other model can be created) and other times afterSave when things are the other way around. afterSave has a helpful parameter so you can know if this was a creation or an update. function afterSave($created) { } In beforeSave you would have to check for the existance of an id in the data (= an update) or not. On Mar 12, 4:51 am, Alex Jeffery <alexanderjeff...@gmail.com> wrote: > Hi, > > I am building a small cake application to learn MVC and cakePHP. > I have a question about where to put business logic, I have read that > controls should be skinny and models should be fat. Eg the business > rules should live in the models. > > In my application I have the following models User, Portfolio, > Currency. > A user has 1 portfolio which has 1 currency. When I register a user I > would like to create their portfolio and assign it the default > currency. > > My question is where to do the creation of the portfolio? > (Fat Controller) > 1. Call the User model to create a new user. > 2. Call the Currency model to get the default currency. > 3. Call the Portfolio model to create a new portfolio for the new user > with the default currency. > > Or > > (Fat Model) > 1. The controller calls a custom function on the Users model. Eg > registerUser($formData) > 2. The User model validates and saves the new user. > 3. The user model then calls the Portfolio model to create a new > portfolio for the new user. > 4. The Portfolio model calls the Currency model to get the default > currency and creates the new portfolio for the new user. > > The advantage I can see to the Fat Model way is that the logic for > registering a new user is all in one spot. > So if I have many controllers that need to register a new user I can > just use the same code. > > Is this on the right track? > > Thanks, > Alex --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---