setData() verses createData() [ Farcry 6.2 ]

20 views
Skip to first unread message

AJ Mercer

unread,
Feb 10, 2014, 9:10:58 PM2/10/14
to farcr...@googlegroups.com
it seems that if createData() is used it does not fire beforeSave()
where as setData() does,
but with setData() you need to create an objectID

Is this correct?

--

AJ Mercer
<webonix:net strength="Industrial" /> | <webonix:org community="Open" />
http://twitter.com/webonix

Jeff Coughlin

unread,
Feb 10, 2014, 9:18:38 PM2/10/14
to farcr...@googlegroups.com
Correct.  The createData() bug has been around for as long as I can remember.  You just have to remember to run beforeSave() manually.

--
Jeff Coughlin

Justin Carter

unread,
Feb 10, 2014, 9:21:51 PM2/10/14
to farcr...@googlegroups.com
Nope, I think the only time Core runs beforeSave() is when a form (or wizard) is processed, and in createFromUpload() (for file/image formtools) - it doesn't get run within createData() or setData(). I'm not entirely happy with the way that part of the API currently works, but it's easy enough to call beforeSave() manually before create/setData().

--
You received this message cos you are subscribed to "farcry-dev" Google group.
To post, email: farcr...@googlegroups.com
To unsubscribe, email: farcry-dev+...@googlegroups.com
For more options: http://groups.google.com/group/farcry-dev
--------------------------------
Follow us on Twitter: http://twitter.com/farcry
---
You received this message because you are subscribed to the Google Groups "farcry-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to farcry-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Jeff Coughlin

unread,
Feb 10, 2014, 9:27:03 PM2/10/14
to farcr...@googlegroups.com
Yeah.  I've gotten used to it being separate and now prefer it in case I ever have the need to not run something like beforeSave().  Although I've never needed it to be separate, I'm sure it can be said that there is a scenario where it might be needed.

--
Jeff Coughlin

AJ Mercer

unread,
Feb 10, 2014, 9:40:13 PM2/10/14
to farcr...@googlegroups.com
Hmmm, ok. Was assuming my beforeSave() was being called, but I put a cfabort in there and it is not called.

I have boolean fields in my custom type,
when createData() is used, they are set to empty string.
when setData() is used, they are set to the (formtool) default


<cfproperty name="bContacted" type="boolean" ftType="boolean" ftDefault="false" required="false" 
ftSeq="210" ftWizardStep="PSL Contact Follow-up" ftFieldset="Update Details" ftLabel="Contacted">

Justin Carter

unread,
Feb 10, 2014, 9:40:19 PM2/10/14
to farcr...@googlegroups.com

Yep, I think the main complaint is that beforeSave and afterSave aren't consistent with each other, and changing one or the other will mean backwards compatibility issues. Tricky one :P

--

Justin Carter

unread,
Feb 10, 2014, 9:44:34 PM2/10/14
to farcr...@googlegroups.com
Hmmm... Perhaps the formtool defaults should be getting applied in createData() but aren't?

Does anything different happen when you add default="false"? e.g.

<cfproperty name="bContacted" type="boolean" ftType="boolean" default="false" ftDefault="false" required="false"
ftSeq="210" ftWizardStep="PSL Contact Follow-up" ftFieldset="Update Details" ftLabel="Contacted">

AJ Mercer

unread,
Feb 10, 2014, 9:49:29 PM2/10/14
to farcr...@googlegroups.com
nope - no difference

What is the reason for having createData()?
What is the difference from setData()?

Justin Carter

unread,
Feb 10, 2014, 9:54:16 PM2/10/14
to farcr...@googlegroups.com
setData() checks first to see if a record exists, so it's less performant (i.e. at least 2 queries for every "insert"), whereas createData() will just try to do an insert. There may by some try/catches in the mix as well.

I haven't looked at the code in detail but they should probably also be consistent in regards to default values, I don't think the resultant data should differ depending on which method you use.

I'm not sure if there's an existing ticket related to this, but perhaps you should create one if there isn't. Also if anyone wants to have a go at fixing it I'm happy to receive pull requests - I'm just swamped at the moment!

cheers,
Justin

AJ Mercer

unread,
Feb 10, 2014, 10:26:58 PM2/10/14
to farcr...@googlegroups.com
is version 7 a good time to consider COAPI changes?

I assumed beforeSave() and afterSaved() would be called by createData()/setData()

should setData() call createData() - or visa versa?

Blair McKenzie

unread,
Feb 10, 2014, 10:31:32 PM2/10/14
to Unname
What is it you want to do in beforeSave? At the moment I'm not sure why beforeSave and createData/setData are separate, or why a developer would use beforeSave instead of simply overriding createData/setData. I would be just as sceptical about afterSave, except that up until recently it was the closest thing FarCry had to a COAPI event.

Blair

AJ Mercer

unread,
Feb 10, 2014, 10:44:18 PM2/10/14
to farcr...@googlegroups.com
I am using beforeSave() to set defaults based on business rules
and afterSave() in, this case, to do something if a business condition is met.

I have not created a custom createData()/setData() as there is nothing I wanted to change about the saving of the data,
and like I said, I assumed before/after where being called by Farcry

Also, if for some reason the set/create fails, I would assume after is not called.

Justin Carter

unread,
Feb 10, 2014, 10:45:43 PM2/10/14
to farcr...@googlegroups.com
At the point in the 7.0 release cycle I don't think we'd consider any changes that would break backwards compatibility for beforeSave/afterSave/createData/setData, we're on the cusp of a release and we have apps that rely on the existing behaviour.

For your particular problem AJ, I think ensuring the defaults get applied consistently in both scenarios (createData/setData) would be a bug fix and there should be no reason we can't do that in 7.0 or in p700 at any time - more than happy for you to raise a JIRA ticket for that.

I assumed beforeSave() and afterSaved() would be called by createData()/setData()
should setData() call createData() - or visa versa? 
 
Unfortunately not... They're just a bit inconsistent in the way they are fired. Perhaps we can resolve this in 7.1... 

For now I'd just do as you're doing, manually call beforeSave, then setData (or create data if you have worked around your boolean problems).


Jeff Coughlin

unread,
Feb 10, 2014, 10:49:05 PM2/10/14
to farcr...@googlegroups.com
I often use before save to modify fields. Example: I often set the label to a mashup of different data fields.

afterSave() I will often use for contacting third-party API's to get data and then set them to fields.  In these cases I protect the fields from formtools by setting bSave() to false so that I can manually save the data myself in afterSave().

Those are just a couple common examples of where I use both methods .

--
Jeff Coughlin

Sean Coyne

unread,
Feb 11, 2014, 2:18:13 PM2/11/14
to farcr...@googlegroups.com
beforeSave() is not called by either setData() or createData().  However, afterSave() is called by setData() but NOT createData().  If you use createData() manually, you should call afterSave() afterwards.  If you use setData() or createData() you should call beforeSave() first.

Sean

Jeff Coughlin

unread,
Feb 11, 2014, 2:20:55 PM2/11/14
to farcr...@googlegroups.com
Yeah. Boggles the mind each time we use it.  Consistency would be nice.

Didn't we have a thread on this already like two or three months ago?

Jeff

Reply all
Reply to author
Forward
0 new messages