Show
Ignore:
Timestamp:
02/12/07 17:09:58 (7 years ago)
Author:
ged
Message:

reorder setup operations. should fix autoload bug.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • elixir/trunk/elixir/relationships.py

    r47 r51  
    164164            self.foreign_key = [self.foreign_key] 
    165165         
    166         #CHECKME: is it of any use to store it somewhere? 
    167166        self.property = None # sqlalchemy property 
    168167         
     
    172171         
    173172        self.entity._descriptor.relationships[self.name] = self 
    174         self.setup_done = False 
    175173     
    176174    def create_keys(self): 
     
    200198            return False 
    201199         
    202         if self.setup_done: 
     200        if self.property: 
    203201            return True 
    204202 
    205 #        FIXME: this should only happen if the relation was not setup already 
    206203        self.create_keys() 
    207204        self.create_tables() 
    208205        self.create_properties() 
    209         self.setup_done = True 
    210206         
    211207        return True 
     
    301297        target_desc = self.target._descriptor 
    302298         
    303         #FIXME: this is buggy, because it seems  
    304         # like the field is used for two different purpose.  
    305         # FK is what? 
    306  
    307         # convert strings to Field instances 
     299        # convert strings to column instances 
    308300        if self.foreign_key: 
    309             self.foreign_key = [source_desc.fields[k] 
     301            #FIXME: this will fail. Because if we specify a foreign_key 
     302            # as argument, it will not create the necessary column 
     303            self.foreign_key = [source_desc.fields[k].column 
    310304                                   for k in self.foreign_key  
    311305                                       if isinstance(k, basestring)] 
     
    366360                source_desc.add_field(field) 
    367361 
    368                 self.foreign_key.append(field) 
     362                self.foreign_key.append(field.column) 
    369363 
    370364                # build the list of local columns which will be part of 
     
    390384         
    391385        if self.entity is self.target: 
     386#            print self.target._descriptor.primary_keys 
     387            #FIXME: this doesn't work for autoload, because primary_keys is 
     388            #empty 
    392389            cols = [k.column for k in self.target._descriptor.primary_keys] 
    393390            kwargs['remote_side'] = cols 
     391#            print "cols", self.name, cols 
    394392 
    395393        kwargs['primaryjoin'] = and_(*self.primaryjoin_clauses) 
     
    411409        kwargs = self.kwargs 
    412410         
    413         #TODO: for now, we don't break any test if we remove those 3 lines. 
     411        #TODO: for now, we don't break any test if we remove those 2 lines. 
    414412        # So, we should either complete the selfref test to prove that they 
    415413        # are indeed useful, or remove them. It might be they are indeed 
     
    417415        # already setup in the other way (belongs_to). 
    418416        if self.entity is self.target: 
    419             #FIXME: this won't work for autoloaded relations 
    420             # so I need to change the type of foreign_key  
    421             kwargs['remote_side'] = [field.column 
    422                                         for field in self.inverse.foreign_key] 
     417            kwargs['remote_side'] = self.inverse.foreign_key 
     418            print "kwargs", self.name, kwargs 
    423419         
    424420        kwargs['primaryjoin'] = and_(*self.inverse.primaryjoin_clauses)