[#3634] Record.into(Table) maps to the wrong table when passing an aliased table after a self-join
This commit is contained in:
parent
79d1560cf6
commit
9cb8d9b030
@ -541,7 +541,7 @@ abstract class AbstractRecord extends AbstractStore implements Record {
|
||||
|
||||
@Override
|
||||
public final Record into(Field<?>... f) {
|
||||
return Utils.newRecord(fetched, Record.class, f, configuration()).operate(new TransferRecordState<Record>());
|
||||
return Utils.newRecord(fetched, Record.class, f, configuration()).operate(new TransferRecordState<Record>(f));
|
||||
}
|
||||
|
||||
// [jooq-tools] START [into-fields]
|
||||
@ -688,15 +688,21 @@ abstract class AbstractRecord extends AbstractStore implements Record {
|
||||
|
||||
@Override
|
||||
public final <R extends Record> R into(Table<R> table) {
|
||||
return Utils.newRecord(fetched, table, configuration()).operate(new TransferRecordState<R>());
|
||||
return Utils.newRecord(fetched, table, configuration()).operate(new TransferRecordState<R>(table.fields()));
|
||||
}
|
||||
|
||||
final <R extends Record> R intoRecord(Class<R> type) {
|
||||
return Utils.newRecord(fetched, type, fields(), configuration()).operate(new TransferRecordState<R>());
|
||||
return Utils.newRecord(fetched, type, fields(), configuration()).operate(new TransferRecordState<R>(null));
|
||||
}
|
||||
|
||||
private class TransferRecordState<R extends Record> implements RecordOperation<R, MappingException> {
|
||||
|
||||
private final Field<?>[] targetFields;
|
||||
|
||||
TransferRecordState(Field<?>[] targetFields) {
|
||||
this.targetFields = targetFields;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R operate(R target) throws MappingException {
|
||||
AbstractRecord source = AbstractRecord.this;
|
||||
@ -708,8 +714,10 @@ abstract class AbstractRecord extends AbstractStore implements Record {
|
||||
AbstractRecord t = (AbstractRecord) target;
|
||||
|
||||
// Iterate over target fields, to avoid ambiguities when two source fields share the same name.
|
||||
for (int targetIndex = 0; targetIndex < t.size(); targetIndex++) {
|
||||
Field<?> targetField = t.field(targetIndex);
|
||||
// [#3634] If external targetFields are provided, use those instead of the target record's fields.
|
||||
// The record doesn't know about aliased tables, for instance.
|
||||
for (int targetIndex = 0; targetIndex < (targetFields != null ? targetFields.length : t.size()); targetIndex++) {
|
||||
Field<?> targetField = (targetFields != null ? targetFields[targetIndex] : t.field(targetIndex));
|
||||
int sourceIndex = fields.indexOf(targetField);
|
||||
|
||||
if (sourceIndex >= 0) {
|
||||
|
||||
@ -93,7 +93,7 @@ class RecordDelegate<R extends Record> {
|
||||
if (configuration != null) {
|
||||
providers = configuration.recordListenerProviders();
|
||||
|
||||
if (providers != null) {
|
||||
if (providers != null && providers.length > 0) {
|
||||
listeners = new RecordListener[providers.length];
|
||||
ctx = new DefaultRecordContext(configuration, executeType(), record);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user