﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
27414	Aliasing ForeignKey fields return integer values, not object	MikiSoft	nobody	"Assuming that Relationship consists of `from_person` and `to_person` ForeignKey fields (which point to User), here's an simple example of showing the actual problem:
{{{#!python
>> results = Relationship.objects.all().annotate(target=F('to_person'))
>> results[0].from_person
<User: second>
>> results[0].target
3
}}}
So, it doesn't work as expected. It should just rename the field, not convert it to the integer type.
The same happens with complex annotations when using conditional expressions (i.e. Case statements). I've even tried like this:
{{{#!python
.annotate(
        person= \
                Case( \
                        When( \
                                to_person__in=friends, \
                                then=F('to_person') \
                        ), \
                        default=F('from_person'),  \
                        output_field=ForeignKey('User') \
                ), \
        target= \
                Case( \
                        When( \
                                to_person__in=friends, \
                                then=F('from_person') \
                        ), \
                        default=F('to_person'), \
                        output_field=ForeignKey('User') \
                ) \
)
}}}
But it still doesn't work. So that's the reason why I think that this is a bug, as I haven't found any explanation for this behavior. In my case in aliased fields I would need objects to be returned, not only IDs of them, therefore I don't know how to solve this."	Bug	new	Database layer (models, ORM)	1.10	Normal				Unreviewed	0	0	0	0	0	0
