emacarron / mybatis

Automatically exported from code.google.com/p/mybatis
0 stars 0 forks source link

feature request: column prefix in association #123

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
My idea is to add parameter "column-prefix" to association tag.
Value of this param should be added to each column element in
resultMap pointed in association.

Thanks to it, we could resolve problem of two associations to object
of the same class (eg person with two fixed addresses).
Now we need to create almost identical resultMaps. There is only one
difference between them: column names. 

Example:

<resultMap type="addressMapper" id="address">
  <id property="id" column="id"/>
  <result property="street" column="street"/>
  <result property="city" column="city"/>
</resultMap>

<resultMap id="personMapper" type="person">
  <id property="id" column="person_id"/>
  <result property="name" column="person_name"/>
  <association property="standingAddress" resultMap="addressMapper" columnPrefix="s_"></association>
  <association property="forwardingAddress" resultMap="addressMapper" columnPrefix="f_"></association>
</resultMap>

<select id="selectPerson">
  SELECT person.id as person_id, 
         person.name as person_name,
         forwardaddress.id as f_id,
         forwardaddress.street as f_street,
         forwardaddress.city as f_city,
         standingaddress.id as s_id,
         standingaddress.street as s_street,
         standingaddress.city as s_city
    FROM person person
    JOIN address forwardaddress 
       ON (forwardaddress.id = person.forward_address_id)
    JOIN address standingaddress
       ON (standingaddress.id = person.standing_address_id)  
</select>

Best regards
Paweł

Original issue reported on code.google.com by piskunow...@gmail.com on 28 Sep 2010 at 3:21

GoogleCodeExporter commented 9 years ago
This would be very usefull indeed!

Original comment by mikee2...@gmail.com on 7 Mar 2011 at 12:21

GoogleCodeExporter commented 9 years ago

Original comment by nathan.m...@gmail.com on 12 Sep 2011 at 3:12

GoogleCodeExporter commented 9 years ago
The attached patch (against r4555) adds new attribute 'columnPrefix' to 
'association' and 'collection' element.

Original comment by haraw...@gmail.com on 9 Jan 2012 at 4:32

Attachments:

GoogleCodeExporter commented 9 years ago
Attached a revised patch.

Original comment by haraw...@gmail.com on 11 Jan 2012 at 4:37

Attachments:

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r4556.

Original comment by haraw...@gmail.com on 13 Jan 2012 at 1:57

GoogleCodeExporter commented 9 years ago

Original comment by haraw...@gmail.com on 13 Jan 2012 at 2:12