Reactor bulk assignment feature?

3 views
Skip to first unread message

Dutch Rapley

unread,
Nov 14, 2008, 3:25:20 PM11/14/08
to reacto...@googlegroups.com
Wouldn't it be fun if we could do something like the following?

<cfset Employee = Reactor.createRecord("Employee")>
<cfset Employee.setProperties(form).save()>

OR

<cfset Employee = Reactor.createRecord("Employee").load(EmployeeID =
form.EmployeeID)>
<cfset Employee.setProperties(form).save()>

The idea is that setProperties would loop through the fieldnames in
the table, and if a corresponding key existed in the structure that's
being passed, it would set that property.

-Dutch

Doug Hughes

unread,
Nov 15, 2008, 10:10:00 AM11/15/08
to reacto...@googlegroups.com
There is something like that... I just have to remember it....  Anyone else remember?

Doug Hughes, President
Alagad Inc.
dhu...@alagad.com
888 Alagad4 (x300)
Office: 919-550-0755
Fax: 888-248-7836

Russ Johnson

unread,
Nov 15, 2008, 10:41:05 AM11/15/08
to reacto...@googlegroups.com
ColdBox has a BeanFactory plugin that can do just that.

Something like:

<cfset Employee = reactor.createRecord("Employee")>
<cfset Employee = getPlugin("beanFactory").populateBean(Employee)>

You could probably take a look the plugin and write your own helper for your application to do the same thing without the framework.

- Russ

Dutch Rapley

unread,
Nov 15, 2008, 12:06:12 PM11/15/08
to reacto...@googlegroups.com
Russ,

ColdBox has a BeanFactory plugin that can do just that.

Thanks for the tip.
 
Something like:

<cfset Employee = reactor.createRecord("Employee")>
<cfset Employee = getPlugin("beanFactory").populateBean(Employee)>

You could probably take a look the plugin and write your own helper for your application to do the same thing without the framework.

And that's exactly what I was getting at. Something I'd like to see in Reactor is to perform a bulk assignment of properties just before a save instead of writing a setter for each property just before a save. Once I get around to getting cozy with the source, it's something I wouldn't mind working on. 

-Dutch

Mark Drew

unread,
Nov 15, 2008, 1:55:56 PM11/15/08
to reacto...@googlegroups.com
In model glue you can do it from an event:

<cfset oEmployee = orm.createRecord("Employee")>

<cfset event.makeEventBean(oEmployee)>
--
Mark Drew

Adobe Community Expert
Blog: http://www.markdrew.co.uk/blog/
LinkedIn: http://www.linkedin.com/in/mdrew

Dutch Rapley

unread,
Nov 17, 2008, 9:00:35 AM11/17/08
to reacto...@googlegroups.com
That. Is. Awesome.

I took a look at the docs - http://docs.model-glue.com/Reference_Materials/Event_API/MakeEventBean(type_any,__fields_list_).htm

Now I assume Russ was talking about the same thing from a Coldbox perspective.

I haven't worked with either Model-Glue or ColdBox yet.

I've worked with Fusebox from versions 2-5 and built my last Fusebox application back in March. Not that I have anything against Fusebox, but I feel it's time for me to move on. Working with Flex the past 6 months, I feel like I have a better understanding of the need for and how to approach development from an event driven perspective. My next non flex app will most likely be developed in either M-G or ColdBox.

-Dutch
--
Dutch Rapley
http://dutchrapley.wordpress.com/

Tom Chiverton

unread,
Nov 18, 2008, 5:06:42 AM11/18/08
to reacto...@googlegroups.com
2008/11/14 Dutch Rapley <dutch....@gmail.com>:

> The idea is that setProperties would loop through the fieldnames in
> the table, and if a corresponding key existed in the structure that's
> being passed, it would set that property.

Ace idea, one for the list.

--
Tom

Tom Chiverton

unread,
Nov 18, 2008, 11:31:43 AM11/18/08
to reacto...@googlegroups.com
>> The idea is that setProperties would loop through the fieldnames in
>> the table, and if a corresponding key existed in the structure that's
>> being passed, it would set that property.
>
> Ace idea, one for the list.

Has anyone added it to trac.reactorframework.org yet ?

--
Tom

Dutch Rapley

unread,
Nov 18, 2008, 12:37:13 PM11/18/08
to reacto...@googlegroups.com
I haven't.

Tom Chiverton

unread,
Nov 19, 2008, 7:04:34 AM11/19/08
to reacto...@googlegroups.com
2008/11/18 Dutch Rapley <dutch....@gmail.com>:
> I haven't.

I have - #192

--
Tom

Mark Drew

unread,
Nov 19, 2008, 7:06:05 AM11/19/08
to reacto...@googlegroups.com
I need to go and setup an RFC area where these features can be added
and discussed upon and a specification be drafter for whoever wants to
develop it.

MD

Tom Chiverton

unread,
Nov 19, 2008, 7:07:56 AM11/19/08
to reacto...@googlegroups.com
2008/11/19 Mark Drew <mark...@gmail.com>:

> I need to go and setup an RFC area where these features can be added
> and discussed upon and a specification be drafter for whoever wants to
> develop it.

At the mo. I'm just marking them as 'enhancment' in trac, is that OK
in the mean time ?

--
Tom

Mark Drew

unread,
Nov 19, 2008, 7:08:32 AM11/19/08
to reacto...@googlegroups.com
Of course

MD

Dutch Rapley

unread,
Jan 15, 2009, 2:42:17 PM1/15/09
to reacto...@googlegroups.com
See my comments:
http://trac.reactorframework.org/ticket/192

As Russ suggested, I was essentially doing (in ColdBox):


<cfset Employee = reactor.createRecord("Employee")>
<cfset Employee = getPlugin("beanFactory").populateBean(Employee)>

But I have an issue with that, as you can't specify what attributes/properties to NOT update on bulk assignment, like the 'id'.

With the setAttributes() method I've written for reactor, I can simply do:
<cfset user = instance.ReactorFactory.createRecord('users').setAttributes(userStructure).save() />

Also, I wrote an interceptor, for ColdBox, to group data into structures based on form field names.

You can specify form field names like
user.firstname
user.lastname
user.email
before the event, a 'user' structure is created in the requestContext.

<cfset user = instance.ReactorFactory.createRecord('users').setAttributes(event.getValue('user')).save() />

If you use ColdBox, you can download the FormInspector interceptor from the ColdBox Code Depot
http://www.coldboxframework.com/downloads/depot/interceptors/FormInspector.zip

-Dutch
Reply all
Reply to author
Forward
0 new messages