﻿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
3885	[multi-db] bug in relating models across different db's	ben	nobody	"I've found what i believe to be a bug when trying to relate models to others in different databases. What seems to be happening is that the wrong opts is being used to build the where clause... So using the following models and query:

Models:
Ticket: postgresql db
WO:     mysql db with the following field:
    ticket = models.ForeignKey(Ticket, db_column='NOCTicket',blank=True, related_name='workorders',maxlength=60)

Query:
t = Ticket.objects.get(pk=2)
qs = t.workorders.all()

I ended up with the following from qs._get_sql_clause():
(['`workorders`.`WorkorderID`',
  '`workorders`.`WorkorderNo`',
  '`workorders`.`RequestorNo`',
  '`workorders`.`ProblemDescription`',
  '`workorders`.`DateReceived`',
  '`workorders`.`ActDateStart`',
  '`workorders`.`ActDateEnd`',
  '`workorders`.`DateRequired`',
  '`workorders`.`EstDuration`',
  '`workorders`.`ActionTaken`',
  '`workorders`.`WorkType`',
  '`workorders`.`CauseDescription`',
  '`workorders`.`PreventionTaken`',
  '`workorders`.`WorkStatus`',
  '`workorders`.`Workpriority`',
  '`workorders`.`AcceptedBy`',
  '`workorders`.`SiteCode`',
  '`workorders`.`NOCTicket`',
  '`workorders`.`NOC`',
  '`workorders`.`AlarmCode`'],
 ' FROM `workorders` WHERE (""workorders"".""NOCTicket"" = %s)',
 [2])

So the select is correct mysql syntax but the where is portgresql syntax.

I'm digging through db.models.query at the moment which I think is where the problem lies, but I'm not all that familiar with this part of the django code. Just to mention as well, I have code from several different branches mixed together too!
Thanks Ben"		closed	Core (Other)	other branch		wontfix	multiple db		Accepted	1	0	0	0	0	0
