(self, model, references)
| 75 | return [] |
| 76 | |
| 77 | def _check_references(self, model, references): |
| 78 | from django.db.models.fields.composite import CompositePrimaryKey |
| 79 | |
| 80 | errors = [] |
| 81 | fields = set() |
| 82 | for field_name, *lookups in references: |
| 83 | # pk is an alias that won't be found by opts.get_field(). |
| 84 | if field_name != "pk" or isinstance(model._meta.pk, CompositePrimaryKey): |
| 85 | fields.add(field_name) |
| 86 | if not lookups: |
| 87 | # If it has no lookups it cannot result in a JOIN. |
| 88 | continue |
| 89 | try: |
| 90 | if field_name == "pk": |
| 91 | field = model._meta.pk |
| 92 | else: |
| 93 | field = model._meta.get_field(field_name) |
| 94 | if not field.is_relation or field.many_to_many or field.one_to_many: |
| 95 | continue |
| 96 | except FieldDoesNotExist: |
| 97 | continue |
| 98 | # JOIN must happen at the first lookup. |
| 99 | first_lookup = lookups[0] |
| 100 | if ( |
| 101 | hasattr(field, "get_transform") |
| 102 | and hasattr(field, "get_lookup") |
| 103 | and field.get_transform(first_lookup) is None |
| 104 | and field.get_lookup(first_lookup) is None |
| 105 | ): |
| 106 | errors.append( |
| 107 | checks.Error( |
| 108 | "'constraints' refers to the joined field '%s'." |
| 109 | % LOOKUP_SEP.join([field_name, *lookups]), |
| 110 | obj=model, |
| 111 | id="models.E041", |
| 112 | ) |
| 113 | ) |
| 114 | errors.extend(model._check_local_fields(fields, "constraints")) |
| 115 | return errors |
| 116 | |
| 117 | def deconstruct(self): |
| 118 | path = "%s.%s" % (self.__class__.__module__, self.__class__.__name__) |
no test coverage detected