Hi Folks,
I've a couple of questions about the best way to handle certain scenarios:
Thanks,
Gareth
****************************************************
This email is sent for and on behalf of Halliwells LLP.
Halliwells LLP is a limited liability partnership registered in England and Wales under registered number OC307980 whose registered office address is at Halliwells LLP, 3 Hardman Square, Spinningfields, Manchester, M3 3EB. A list of members is available for inspection at the registered office together with a list of those non members who are referred to as partners. We use the word “partner” to refer to a member of the LLP, or an employee or consultant with equivalent standing and qualifications. Regulated by the Solicitors Regulation Authority.
CONFIDENTIALITY
This email is intended only for the use of the addressee named above and may be confidential or legally privileged. If you are not the addressee you must not read it and must not use any information contained in nor copy it nor inform any person other than Halliwells LLP or the addressee of its existence or contents. If you have received this email in error please delete it and notify Halliwells LLP IT Department on 0870 365 2500.
For more information about Halliwells LLP visit www.Halliwells.com.
Thanks for the tips.
I think I'll go with my custom save() method for question 1.
I had a look at the link, but the attachDelegate() method has been removed from reactor. A later email from Doug mentions that the event model was re-done when iterators were added. I'm not sure the difference of over-writing beforeSave() and afterSave() with just over-writing save()?
For question 2, I'd prefer to put the solution in the record. I can't guarantee that the User record wouldn't be saved directly instead of through a service layer every time.
I'm guessing I could build a custom load() method that stores the value of 'name' after a load occurs. A custom save() method could then check if this has changed, and call other code if necessary. I'll see how this works later this week.
Thanks,
Gareth
****************************************************
This email is sent for and on behalf of Halliwells LLP.
Halliwells LLP is a limited liability partnership registered in England and Wales under registered number OC307980 whose registered office address is at Halliwells LLP, 3 Hardman Square, Spinningfields, Manchester, M3 3EB. A list of members is available for inspection at the registered office together with a list of those non members who are referred to as partners. We use the word ?partner? to refer to a member of the LLP, or an employee or consultant with equivalent standing and qualifications. Regulated by the Solicitors Regulation Authority.
CONFIDENTIALITY
This email is intended only for the use of the addressee named above and may be confidential or legally privileged. If you are not the addressee you must not read it and must not use any information contained in nor copy it nor inform any person other than Halliwells LLP or the addressee of its existence or contents. If you have received this email in error please delete it and notify Halliwells LLP IT Department on 0870 365 2500.
For more information about Halliwells LLP visit
For this project, all database interaction is done via reactor.
In addition to calling User.save() directly, a User record could be saved indirectly e.g. AnotherRecord.getUserIterator().save().
By having this logic directly in the custom User record, I feel more confident that it will always be executed when necessary.
I'm not sure if this is the best way to do things, but I use model-glue and it's scaffolding to speed up development. Keeping logic like this in custom reactor objects seems to be the easiest way to handle things
-----Original Message-----
From:
reacto...@googlegroups.com [mailto:reacto...@googlegroups.com] On Behalf Of Tom Chiverton
Sent: 02 September 2009 15:18
To: reacto...@googlegroups.com
Subject: [reactor-users] Re: 2 reactor
questions
On Wednesday 02 Sep 2009, Gareth Cole wrote:
The solution to question 2 turned out to be quite simple after I discovered the _getInitialTo() method in records.
All I needed to do was add a custom executeSave() method:
<cffunction name="executeSave" access="private" hint="Over-write this function, to check for changes to name" output="false" returntype="void">
<cfscript>
var changed = (_getTO().name NEQ _getInitialTO().name);
super.executeSave();
if (changed){
getNewPassport();
}
</cfscript>
</cffunction>
The important thing was to check if the field changed BEFORE calling super.executeSave(), as that method resets the initial TO.
I love the power of reactor. I can build a sophisticated, robust project model with minimum of effort!
-----Original Message-----
From:
reacto...@googlegroups.com [mailto:reacto...@googlegroups.com] On Behalf Of Gareth Cole
Sent: 01 September 2009 18:11
To: reacto...@googlegroups.com
Subject: [reactor-users] 2 reactor
questions
Hi Folks,
I've a couple of questions about the best way to handle certain scenarios:
1. I've got a Rota record. To this record, I've added a custom function called updateShifts(). I want this function to be executed every time the record is saved, after the save has been done. I thought about over-writing the save() method, calling super.save() and then updateShifts(). However, I also saw an afterSave() method that may be more appropriate to over-write. afterSave() already seems to have a lot of code in it, so I wasn't sure if it's safe to over-write. What's the recommended way of doing this?
2. I'd like to trigger another custom function if one record property is changed and then saved. As an example, my User record has various fields, one of which is 'name'. If the name is changed and saved, a custom function in the record called getNewPassport() should be executed. Again, I suspect over-writing afterSave() may be the answer, but I've no idea how to monitor the field to see if it changed. Any thoughts?
Thanks,
Gareth