Hi Benjamin,

Thanks for your enquiry.

This is indeed related, although, it works as designed. The reason why jOOQ
allows for non-exact matches of Field<?> references in these situations is
because this makes accessing fields from aliased tables, automatically (by
jOOQ) aliased tables, derived tables, common table expressions, etc. much
easier and less verbose.

In fact, from a more formal perspective, SQL result sets don't have
qualified column names. Names are always unqualified, and sometimes even
disambiguated with suffixes in certain drivers / tools. Nested queries are
not allowed to contain ambiguous column names at all, so from a pure SQL
perspective, jOOQ's implementation makes even more sense.

Recent bug fixes have resolved issues where the above approach was
"ambiguous" (e.g. multiple Id columns), in case of which the exact match is
always preferred.

Unfortunately, we cannot really change this behaviour right now as many
applications already depend on it. I'm aware that this is a frequent source
of confusion, which means there's probably a better way, but we haven't
found one yet. I'm (as always) very open for discussion, though.

Best Regards,
Lukas

2016-07-07 14:37 GMT+02:00 <[email protected]>:

> Hi Lukas,
>
> is this the same problem while using the following ?
>
> create.select(A.Id).from(A).leftjoin(B).on(B.Id.eq(A.B_Id))
>
> TableARecord tableARecord = record.into(TableA);
> TableBRecord tableBRecord = record.into(TableB);
>
> long idA = tableARecord.get(TableA.Id);
> long idB = tableBRecord.get(TableB.Id);
>
> In this case if only A.Id is selected, both get methods return the same
> id. I find this
> very confusing because i would expected the record class to know which id
> is associated
> with its table ...
>
> Is there a good workaround to this behaviour or a setting to avoid it ?
>
> - Best regards Benjamin
>
>
> Am Samstag, 25. Juni 2016 14:37:35 UTC+2 schrieb Lukas Eder:
>>
>> Hello Nico,
>>
>> You could check for equality after getting the field from the record:
>>
>> B.B_ID.equals(record.field(B.B_ID))
>>
>>
>> That might look a bit fishy at first but it makes sense as it uses the
>> API contract stating that record.field(Field) returns a Field of the same
>> Field.getName(), regardless if the resulting Field really equals() the
>> argument field.
>>
>> Hope this helps,
>> Lukas
>>
>> 2016-06-23 11:39 GMT+02:00 McNetic <[email protected]>:
>>
>>> Hi,
>>>
>>> I have two tables aggregated by a foreign key. Sometimes I just need
>>> table A, sometimes I want the corresponding record from table B to be
>>> filled in a member variable. So my SELECTs are like
>>> create.select().from(A).where(...)
>>> or
>>> create.select().from(A).leftJoin(B).on(A.B_ID.eq(B.B_ID))
>>>
>>> Now, I want the RecordMapper to decide wether to fill a member of object
>>> A with an object B created from the record based on the existance of B.B_ID
>>> in the record. Is there any way to determine if B.B_ID is present?
>>> record.field(B.B_ID)
>>> will always be != null because of A.B_ID also being present in the
>>> record.
>>> record.field("B.B_ID")
>>> is always null.
>>>
>>> Is there any other way to achieve what I want to do?
>>>
>>> Thank you very much
>>>
>>> Nico
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "jOOQ User Group" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "jOOQ User Group" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "jOOQ 
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to