diff -r 41150ab49bb8 django/db/models/fields/related.py
a
|
b
|
|
835 | 835 | if value is None: |
836 | 836 | return |
837 | 837 | |
838 | | qs = self.rel.to._default_manager.filter(**{self.rel.field_name:value}) |
| 838 | using = router.db_for_read(model_instance.__class__, instance=model_instance) |
| 839 | qs = self.rel.to._default_manager.using(using).filter( |
| 840 | **{self.rel.field_name: value} |
| 841 | ) |
839 | 842 | qs = qs.complex_filter(self.rel.limit_choices_to) |
840 | 843 | if not qs.exists(): |
841 | 844 | raise exceptions.ValidationError(self.error_messages['invalid'] % { |
diff -r 41150ab49bb8 tests/regressiontests/multiple_database/tests.py
a
|
b
|
|
581 | 581 | self.assertEquals(Person.objects.using('other').count(), 0) |
582 | 582 | self.assertEquals(Pet.objects.using('other').count(), 0) |
583 | 583 | |
| 584 | def test_foreign_key_validation(self): |
| 585 | "ForeignKey.validate() uses the correct database" |
| 586 | mickey = Person.objects.using('other').create(name="Mickey") |
| 587 | pluto = Pet.objects.using('other').create(name="Pluto", owner=mickey) |
| 588 | self.assertEquals(None, pluto.full_clean()) |
| 589 | |
584 | 590 | def test_o2o_separation(self): |
585 | 591 | "OneToOne fields are constrained to a single database" |
586 | 592 | # Create a user and profile on the default database |