Django

Code

Changeset 3447

Show
Ignore:
Timestamp:
07/25/06 13:37:05 (2 years ago)
Author:
jpellerin
Message:

[multi-db] Added check in model validation for models related to other
models using a different connection. Removed special-case stringifying
of _default connection.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/multiple-db-support/django/core/management.py

    r3444 r3447  
    263263            if not statements: 
    264264                continue 
    265             if connection_name is _default: 
    266                 connection_name = '(default)' 
    267265            final_output.append(' -- The following statements are for connection: %s' % connection_name) 
    268266            if reverse: 
     
    682680    Returns number of errors. 
    683681    """ 
    684     from django.db import models 
     682    from django.db import models, model_connection_name 
    685683    from django.db.models.loading import get_app_errors 
    686684    from django.db.models.fields.related import RelatedObject 
     
    693691    for cls in models.get_models(app): 
    694692        opts = cls._meta 
    695  
     693        connection_name = model_connection_name(cls) 
     694         
    696695        # Do field-specific validation. 
    697696        for f in opts.fields: 
     
    730729                if f.rel.to not in models.get_models(): 
    731730                    e.add(opts, "'%s' has relation with model %s, which has not been installed" % (f.name, rel_opts.object_name)) 
     731 
     732                rel_connection = model_connection_name(f.rel.to) 
     733                if rel_connection != connection_name: 
     734                    e.add(opts, "'%s' is configured to use connection '%s' but has relation with '%s', which is configured to use connection '%s'" % (cls.__name__, connection_name, f.rel.to.__name__, rel_connection)) 
    732735 
    733736                rel_name = RelatedObject(f.rel.to, cls, f).get_accessor_name()