Changes to Model._get(), Model._set(), and Model.populate().

1 view
Skip to first unread message

Tony Nelson

unread,
May 9, 2011, 10:13:52 PM5/9/11
to ColdMVC
Recently I stumbled upon an issue with hidden reserved function names
in ColdFusion (see:
http://www.coldfusionjedi.com/index.cfm/2011/5/9/Interesting-issue-with-reserved-function-names-inside-CFCs).
Because of this, I've decided to make some non-backwards compatible
changes to ColdMVC.

First, I'm removing the Model._set(key, value) and Model._get(key)
methods from the base model (coldmvc.Model) and replacing them with a
single Model.prop(key [, value]) method. The prop() method works
similar to prop() and attr() in jQuery, where the method is both a
getter or a setter depending on the number of arguments.

Second, I've decided to perform some general maintenance on the
Model.populate() method. Previously, there was some relatively cryptic
logic that attempted to be smart about what you were trying to do by
modifying the incoming arguments. For example, it would remove
underscores and trim off a trailing "ID" if the property couldn't be
found. For example, user.populate(firstName="Tony") and
user.populate(first_name="Tony") would be equivalent. While this could
be considered useful by some people, in my opinion it encourages
sloppiness in naming conventions. Since this is a convention-based
framework, I'm choosing to side in favor of strong conventions.

Now, populate() simply loops over the incoming struct and delegates
all population responsibility to the prop() method, which in turn
delegates to the base DAO. While this doesn't really affect you
directly, the code behind the scenes is much cleaner and easier to
test.

I'm going to be checking these changes into GitHub tonight as part of
version 1.2.0. Let me know if you have any questions.

Joe Banken

unread,
May 9, 2011, 10:49:40 PM5/9/11
to col...@googlegroups.com

Thx for the update.

Ryan Ricard

unread,
May 10, 2011, 9:28:28 AM5/10/11
to ColdMVC
A couple questions...

Is the removal of Model._set()/Model._get() and the addition of
Model.prop() going to affect property getters and setters in any way?

Regarding Model.populate()... so basically, keys passed to
Model.populate() will need to mirror model property names, correct?

Thanks for the update Tony.

Ryan


On May 9, 9:13 pm, Tony Nelson <tonynelso...@gmail.com> wrote:
> Recently I stumbled upon an issue with hidden reserved function names
> in ColdFusion (see:http://www.coldfusionjedi.com/index.cfm/2011/5/9/Interesting-issue-wi...).

Tony Nelson

unread,
May 10, 2011, 9:33:48 AM5/10/11
to col...@googlegroups.com
Property getters and setters will be left unaffected and will function the same as before. In truth, calling user.foo() is exactly the same as calling user.prop("foo") - behind the scenes they both call DAO.getProperty(user, "foo"). Personally I find user.foo() to read a lot cleaner, but user.prop("foo") is better when you're working with dynamic property names so you don't have to call evaluate("user.#prop#()").

As for populate(), yes the keys should match the property names.

-Tony

Ryan Ricard

unread,
May 10, 2011, 9:40:03 AM5/10/11
to ColdMVC
Thanks Tony. I'm on-board.
Reply all
Reply to author
Forward
0 new messages