开发者

Is it possible to combine annotations with defer/only in django 1.2.1?

I have two simple models: Book, and Author

Each Book has one Author, linked through a foreignkey.

Things work normally until I try to use defer/only on an annotation:

authors=Author.objects.all().annotate(bookcount=Count('books'))

that works. The query looks like:

select table_author.name, table_author.birthday, COUNT(table_book.id) as bookcount 
from table_book left outer join table_author on table_author.id=table_book.author_id 
group by table_author.id

so very simple - selecting everything from author, and additionally selecting a count of the books.

But when I do the following, everything changes:

simple=authors.defer('birthday')

now, the simple query looks like this:

select COUNT(t开发者_如何转开发able_book.id) as bookcount from table_book left outer join 
table_author on table_author.id=table_book.author_id group by table_author.id

and it has completely lost the extra information. What's the deal?


Well, this would seem to be a bug. There's already a ticket, but it hasn't had much attention for a while. Might be worth making a post to the django-developers Google group to chivvy things along.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜