AfterFind on outer joined model returns empty object
Author.cfc Model
hasOne(name="Post", joinType="outer");
Controller
author = model("Author").findOne(include="Post");
When the controller queries the author, and the author has no post, a post object is returned containing all empty properties.
https://groups.google.com/forum/?fromgroups=#!topic/cfwheels/KSHSji3QwAs
- Discovered by @lmah
Will investigate for 1.4.2.
Would be good to have a failing test for this one.
If I do this with a hasMany association instead: author = model("Author").findOne(include="posts");
I get a "posts" array with no elements.
Given that it perhaps makes sense that a hasOne association returns an empty object?
If not, do I change both of the above to not even add the "post" / "posts" element to the returned base object?
A compromise might be to return the empty object but with no properties added to it (as opposed to empty properties).
That would make it more similar to the empty "posts" array I guess.
Thinking about this, if an object with no properties were returned, would this break nested objects in forms? http://docs.cfwheels.org/docs/nested-properties
@chrisdpeters Any thoughts on this one?
It likely would cause validation to fail when updating an object with nested properties (but in boundary cases where no data is set for that object).
I'm pretty sure that Rails returns nil in this case. Should we set the property to false to stay consistent with how findOne and findByKey behave?
I think it makes sense to change the milestone on this one since it may cause backward compatibility issues.