Can anyone explain why a column alias is being created in the WHERE clause in this scenario?
In attempting to learn the Criteria Builder -- and Coldbox/ColdFusion in general -- I noticed that when I refer to a property named “name” from my User model from within the .withProjections() then the SQL WHERE clause that is sent to SQL Server contains an alias instead of the actual column name.
So if I have a User model like this:
component persistent="true" table="Users" {
// Primary Key
property name="ID" fieldtype="id" column="ID" generator="native" setter="false";
// Properties
property name="code" column="Code" ormtype="string";
property name="name" column="Name" ormtype="string";
...
}
Then I do something like this in my Users handler:
var users = c.$and(c.restrictions.like("name", userName & "%"),c.restrictions.eq("status","Active")).withProjections(property="name, code").list();The SQL that is generated is:
select
this_.Name as y0_,
this_.Code as y1_
from
schema.Users this_
where
(
y0_ like ?
and this_.Status=?
)And I get a SQL Server error message:
Invalid column name 'y0_'.But, if I alias that name property and change my Criteria to:
var users = c.$and(c.restrictions.like("name", userName & "%"),c.restrictions.eq("status","Active")).withProjections(property="name:userName, code").list();Then the SQL is generated appropriately and I get the results I expect:
select
this_.Name as y0_,
this_.Code as y1_,
from
schema.Users this_
where
(
this_.Name like ?
and this_.Status=?
)Can anyone explain why a column alias is being created in the WHERE clause in the above scenario? It would be nice to know what to watch out for ahead of time rather than me having to alias every property or just wait until errors happen.
Similar revelations found here.
Thanks!
Wes
--
--
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
For News, visit http://blog.coldbox.org
For Documentation, visit http://wiki.coldbox.org
For Bug Reports, visit https://ortussolutions.atlassian.net/browse/COLDBOX
---
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coldbox+u...@googlegroups.com.
To post to this group, send email to col...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.