SqlSoup - Error in relate

191 views
Skip to first unread message

temo

unread,
Mar 24, 2012, 12:47:14 AM3/24/12
to sqlal...@googlegroups.com
Hi

Im mapping a database with sqlsoup and when use db.relate shows this error:

sqlalchemy.exc.ArgumentError: Could not determine join condition between parent/child tables on relationship MappedCatalog_unit.catalog_product.  Specify a 'primaryjoin' expression.  If 'secondary' is present, 'secondaryjoin' is needed as well.


this a sample of how looks the relationship in data base

catalog_unit:
name = char()

catalog_product:
unit_purchase = ForeignKey(catalog_unit)
unit_sale = ForeignKey(catalog_unit)

anyone knows how fix it?



Michael Bayer

unread,
Mar 24, 2012, 12:53:14 AM3/24/12
to sqlal...@googlegroups.com
you'd need to specify join conditions as they occur in an example like this one:


relate() should accept the same arguments as relationship().

the source of the issue is probably that you're on MySQL using MyISAM tables, which do not store any information about FOREIGN KEY constraints and thus SQLAlchemy doesn't know they exist when SQLSoup reflects the structure of the tables from the database.




--
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To view this discussion on the web visit https://groups.google.com/d/msg/sqlalchemy/-/7hRFVPz7MssJ.
To post to this group, send email to sqlal...@googlegroups.com.
To unsubscribe from this group, send email to sqlalchemy+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.

temo

unread,
Mar 24, 2012, 11:38:06 PM3/24/12
to sqlal...@googlegroups.com
no, i'm on postgresql, the tables was generated django with syncdb,

i see the example, and change relate() to this:
self.db.catalog_unit.relate('catalog_product', self.db.catalog_product, 
            primaryjoin="catalog_product.id==catalog_unit.unit_purchase_id", cascade='all, delete-orphan') 

shows this error:
sqlalchemy.exc.ArgumentError: Column-based expression object expected for argument 'primaryjoin'; got: 'catalog_product.id==catalog_unit.unit_purchase_id', type <type 'str'>

so, i have to create the tables with Base, like this??:

class Unit(Base):
    __tablename__ = 'catalog_unit'
    id = Column(Integer, primary_key=True)
    name = Column(String)

   ....
To unsubscribe from this group, send email to sqlalchemy+unsubscribe@​googlegroups.com.

Michael Bayer

unread,
Mar 25, 2012, 1:49:15 AM3/25/12
to sqlal...@googlegroups.com
Yeah this is really not an easy use case with SQLSoup, you can't use the string form "" and really if your database has FOREIGN KEY on "unit_purchase_id" you shouldn't need to be doing this anyway - you'd want to check in your PGAdmin tool to see if there is in fact an FK constraint on this column.

or just try losing the "" :

primaryjoin=catalog_product.id==catalog_unit.unit_purchase_id

anyway this is why SQLsoup is spun off as it's own project now (it won't be in SQLAlchemy 0.8), it really needs someone to maintain/document it as it's very old.


To view this discussion on the web visit https://groups.google.com/d/msg/sqlalchemy/-/-Wp6NEFIpA8J.

To post to this group, send email to sqlal...@googlegroups.com.
To unsubscribe from this group, send email to sqlalchemy+...@googlegroups.com.

temo

unread,
Mar 26, 2012, 2:56:33 AM3/26/12
to sqlal...@googlegroups.com
with the sqlalchemy tables it works, but i dont like solution :P, now i have to map all tables :/

thanks for your time :)
Reply all
Reply to author
Forward
0 new messages