john, thank you for taking the time to perform those tests. yes,
returning objects is going to be slow, but as you stated, this is a
problem with creating a large number of objects in CFML and not
necessarily a wheels problem.
per is on target (as always) with his statement that most people
probably return objects because they want access to a method that on
that object.
one thing i feel people forget about is using afterFind callbacks on
you models. afterFind callbacks let you specify logic in a method that
gets attached as columns when returning queries and properties when
returning objects. this can really help you to avoid having to return
objects in your application. obviously afterFind callbacks won't fit
every situation, but for the more common situations that people create
custom methods and calculated properties on an object, they can really
help out.
a perfect example is that most people will either create a method or
calculated property to concatenate a user's first and last name into a
fullname string. the issue with using a calculated property for
something like is that you have to write database specific logic that
isn't portable and creating a custom method forces you to have to
create an object in order for the method to be accessed. by creating
an afterFind callback you can avoid all of this and still have the
logic you need in both queries and object properties.
i use afterFind callbacks quite a bit in my models and i'm amazed by
them. i strongly feel that they're one of the little known, forgotten
features that make using wheels a pleasure.
On Mar 29, 6:24 am, Per Djurner <
per.djur...@gmail.com> wrote:
> I agree, it's a dangerous path to go when you start returning objects for no
> good reason.
>
> I have actually never used "returnAs" in my apps, I'm sticking to the
> defaults to 100%.
> The only situation where you'd want to use returnAs="object(s)" is when you
> need to fetch multiple related objects because you plan on using them in
> a Nested Properties form.
>
> Another common (but bad) reason people return multiple objects is because
> they want to run methods on them.
> This would seem to make total sense at first glance of course but in a
> procedural/object-oriented hybrid framework like Wheels it's (in my opinion)
> a much better idea to use Calculated Properties, for example, to work around
> this limitation.
>
> Sometimes I wish we'd never added the "returnAs" argument... this would've
> more clearly positioned / articulated Wheels as a hybrid framework versus
> one where you strive to deal with objects all the time.
>
> / Per
>
> On Tue, Mar 29, 2011 at 11:23 AM, John C. Bland II
> <
johncblan...@gmail.com>wrote:
> > ab -n 1000 -c 10
http://my-ec2.com/?controller=api&action=index