Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
DataMapper 1.6.1
-
None
Description
Detected by Miika Mäkinen, Nicholas Piaseck
I have a Coupon class that contains an integer list of BrandIds that
specifies which brands of product the coupon is good for. We don't want
the whole Brand object because it contains a lot of information that's
not necessary for the coupon's CalculateDiscount() method to function,
so we'd just like a list of integers returned from iBATIS. int[],
List<int>, just a list of integers of some sort.
The relevant parts of the database tables look like this:
Coupons:
CouponId (PK)
Code
Coupons_Brands: (M:N relationship table)
CouponId (FK)
BrandId (FK)
To avoid the N+1 selects, we tried a SQL statement like the following:
SELECT
cou.CouponId AS CouponId,
cou.Code AS CouponCode,
cou_b.BrandId AS CouponBrandId,
FROM SkiviezInv.Coupons AS cou
LEFT OUTER JOIN Coupons_Brands AS cou_b
ON cou.CouponId = cou_b.CouponId
But then we got stuck at defining the <resultMap>. Just using the
property and column attributes doesn't work ("no type handler for List`1
is registered"). The furthest we got was defining another result map for
the integer type, like this:
<resultMap id="ResultMapCoupon" class="Coupon" groupBy="Id">
<result column="CouponId" property="Id" />
<result
property="BrandIds"
resultMapping="Coupon.ResultMapCouponBrandId" />
</resultMap>
<resultMap id="ResultMapCouponBrandId" class="int">
<result property="value" column="CouponBrandId" />
</resultMap>
This set up would indeed create a List<int> with the proper Count (e.g.,
two BrandIds), but they're always all set to 0. I