title: SQLAlchemy How to map single column of one-to-one relationship using declarative
body: <p>This is related to this question <a href="https://stackoverflow.com/questions/2382755/converting-to-declarative-method-and-column-property">converting to declarative method and column property</a>, which has never been answered. </p>
  
  <p>We are trying to set up a Flask-SQLAlchemy project on an existing schema (one we cannot change), and decided on the declarative syntax so that we can organize the classes into multiple files in a sane way for maintenance. This works for most of our relationships except for something that we call, for lack of a better term, attribute tables. These are one-to-one leaf tables off some primary object, and typically contain some kind of controlled vocabulary for the attribute. The goal in the ORM is to map all of these (of which there are many) types of tables as if they were properties of the primary table.</p>
  
  <p>Here is an SQA example with two tables:</p>
  
  <pre><code>class MarkerType(db.Model):
      __tablename__="mrk_types"
      _marker_type_key = db.Column(db.Integer,primary_key=True)
      name = db.Column(db.String())
  
  class Marker(db.Model):
      __tablename__="mrk_marker"
      _marker_key=db.Column(db.Integer,primary_key=True)
      _marker_type_key=db.Column(db.Integer())
  </code></pre>
  
  <p>We want to access MarkerType.name as if we were saying Marker.markertype, or in a query as Marker.markertype=='thing'. The only way I could manage that is with a column_property in the Marker class, like so:</p>
  
  <pre><code>markertype = db.column_property(
              db.select([MarkerType.name]).
              where(MarkerType._marker_type_key==_marker_type_key)
      )
  </code></pre>
  
  <p>However, I cannot seem to find how to do this in a declarative way, and maybe that way does not exist. Is there a sane way I can achieve this without having to worry about my imports, or even worse the order of my classes? Since we have hundreds of tables to map, I can see this being a maintenance nightmare if we have to worry about class and import order. </p>
  
  <p>If all of this is totally impossible, wishful thinking, what is a better approach to mapping these tables?</p>