Mike, what you set forth is more of what I was actually trying to
bring into the discussion (having used that same technique myself),
rather than the link I gave above.  I need to get more sleep and check
my doc references more carefully!


On Nov 11, 1:39 pm, Mike Conley <mconl...@gmail.com> wrote:
> If it's simply a matter of sequence of how code is organized:
>
> 1. Define Merchants table and mappers
> 2. Define Deals table and mappers
> 3. Add relations to Merchant
> All of this can be in separate files if needed; just import right
> definitions where needed.
>
> metadata = MetaData()
>
> merchants = Table('merchants', metadata,
>     Column('id', Integer, primary_key=True),
>     Column('name', String)
>     )
>
> class Merchant(object):
>     pass
>
> mapper(Merchant, merchants)
>
> deals = Table('deals', metadata,
>     Column('id', Integer, primary_key=True),
>     Column('merch_id', Integer, ForeignKey('merchants.id')),
>     Column('deal_status', String(10))
>     )
>
> class Deal(object):
>     pass
>
> mapper(Deal, deals)
>
> Merchant.all_deals = relation(Deal, backref='merchant')
> Merchant.active_deals = relation(Deal, primaryjoin=
>                 and_(merchants.c.id==deals.c.merch_id,
>                 deals.c.deal_status=='active'))
>
> This is one advantage of using declarative because the primaryjoin can be
> defined as a string that will not be compiled until later. That can be
> deferred until after everything is defined.
>
> --
> Mike Conley
>
> On Thu, Nov 11, 2010 at 1:33 PM, Jonathan Gardner <
>
> jgard...@jonathangardner.net> wrote:
> > This is what I need to do, except the Merchant object is defined
> > before the Deal object. In the example in the documentation, I have
> > mapped User before I have mapped Address.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to