On Feb 2, 2006, at 3:04 PM, Michael Bayer wrote:
the mapper() object allows you to specify a primary_key on the mapper, as it relates to its selectable:

        s = mytable.select(table.c.col1==5)

        m = mapper(s, primary_key=[s.c.id])

so you can stick a straight table or an aliased selectable right into a mapper the same way; its just if the selectable you are sending in does not have a natural primary key (or the primary key that you want), you have to tell the mapper what columns comprise the primary key, which will override whatever it gets from the selectable.

i was hoping to avoid that; currently i have
something like:

def mkmap(cls, sel):
        m = mapper(cls, sel)
        # do prop work
        return m

i was hoping to avoid making this:

def mkmap(cls, sel):
        if isinstance(sel, Table):
                m = mapper(cls, sel)
        else:
                # pkcol comes from somewhere;
                # (this is just outline code)
                m = mapper(cls, sel, primary_key=[pkcol])
        # do prop work
        return m

All of the SQL objects, the three big ones Alias, Join, Select, (as well as of course Table), do in fact have a primary_key attribute, which in all cases is defined as the aggregate of all primary_key columns found in the underlying selectables they represent.

hmm; i'm probably doing something wrong such that
the pk's aren't propagating up properly ...

is it bad to define a Table on what is actually
a view in the backend?

thx, d



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to