SQLAlchemy equivalent to Active Record has_one_through -
sqlalchemy's docs great little overwhelming @ times coming rails , active record.
given active record relationship set sqlalchemy equivalent establish relationship through intermediary table?
specifically given basic active record example below i'm trying understand how define equivalent relationship in sqlalchemy can allow account sqlalchemy model tied accounthistory model. i'm not clear if i'm supposed using mapper function , feel i'm missing simple in sqlalchemy.
class supplier < activerecord::base has_one :account has_one :account_history, through: :account end class account < activerecord::base belongs_to :supplier has_one :account_history end class accounthistory < activerecord::base belongs_to :account end
perhaps misunderstood workings of has_one_through
. in retrospect think looking this:
class supplier(base): __tablename__ = 'supplier' id = column(integer, primary_key=true) class accounthistory(base): __tablename__ = 'account_history' id = column(integer, primary_key=true) account_id = column(integer, foreignkey('account.id')) class account(base): __tablename__ = 'account' supplier_id = column(integer, foreignkey('supplier.id'))
Comments
Post a Comment