I think the confusion is my fault. When I first reported this issue, I
had only been working with ORM for a few days. The snippet of the
WHERE clause in that block of code, was my final attempt to get the
code to work as I expect. It shouldn't have been there in the example.
After all I've learned this week, I now understand the problem to
simply be exactly what Daniel T. encountered here:
http://stackoverflow.com/questions/7680025/discriminator-not-used-in-sql-for-one-to-many-mapping-in-coldfusion-orm
(his example uses a Store with various Products)
Basically, when you have various types of 'things' (Fruits and
Vegetables in his case) in your cross-reference table, you should be
able to use a discriminator (as the documentation states) to choose
the type of 'thing' you want from the xref.
This works well when you are instantiating the Fruit by itself--
Hibernate uses the discriminator value to choose the appropriate item.
You receive a Fruit, which is an extension of Product.cfc.
CF ORM does not discriminate on Fruits when you instantiate the Store
[o2m <- Fruit].
The expected behavior here is that the you should receive a Store
object composed with an array of Fruits. What you get is a Store
composed with an array of Fruit objects, BUT the Fruit objects
represent ALL Products, not just Fruits -- Hibernate does not apply
the discriminator to choose the appropriate item. Inspecting the SQL
proves this: there is no WHERE clause in the SQL to discriminate
amongst the Products.
Daniel T got around this by creating a Fruit <m2o> Store on the Fruit
object (filtering by Store on the Fruit, see his examples). I'm unable
to use this solution as it doesn't fit the business model.
Ideally, I would rewrite the database tables to make more sense. But
since that's not possible, I'm getting around this issue by explicitly
adding a WHERE clause to the User's 'employment' property.