yeah....heh ok this one was a somewhat easy fix that became a pretty big cascading issue.  but its fixed in 1635, the commit message should say it all for that one.

short version:  instead of using NULL in the union to match up columns that dont exist, it uses CAST(NULL as <sometype>) based on the type of the real columns in the UNION.

longer version: MySQL doesnt really seem to support CAST very much

On Jun 16, 2006, at 3:53 PM, Koen Bok wrote:

The inserts work great. But when I try to do a select query it fails with postgres. Sqlite works fine though.

Script included.

Error message:

sqlalchemy.exceptions.SQLError: ('(ProgrammingError) UNION types text and integer cannot be matched\n',)


<polymorph.py>

On 16-jun-2006, at 21:03, Michael Bayer wrote:

you got it...small fix to some foreign key arithmetic in changeset 1630.

also you need to have the "from_stock" member on your InternOrder:

session.save(InternOrder(
employee=e1,
from_stock=Stock(location=Location(name='Germany'), name='SomethingElse', sellable=True),
to_stock=Stock(location=Location(name='Amsterdam'), name='Main', sellable=True)))


On Jun 16, 2006, at 12:39 PM, Koen Bok wrote:

Haha! I did exactly that this day! And it is indeed VERY cool.

I had the roof house thing working and now I am trying to implement my first question. It works, but I keep bumping into the same problem when I try to link to two tables within a polymorphic mapped class.

I think this is a bug. I included ready to roll python files.

If this is going to work, I'll be so happy!

<broken.py>
<works.py>


On 16-jun-2006, at 18:28, Michael Bayer wrote:

this assumes each House will point to a unique Roof object (i.e., its a one-to-one relationship to a Roof).  also if you use the latest trunk (or 2.3 when i release it this weekend) you can declare the mappers in any order.

houses
----------
house_id  integer pk
name       varchar

roofs
-------
roof_id integer pk
house_id integer references houses(house_id)    -- or put roof_id on the houses table, same diff
name varchar
type  varchar

concrete_roofs
--------------------
roof_id integer pk references roofs(roof_id)
hardness varchar

wood_roofs
----------------
roof_id integer pk references roofs(roof_id)
treename varchar

metadata = BoundMetaData('some://db')

(houses, roofs, concete_roofs, wood_roofs) = [Table(name, metadata, autoload=True) for name in ['houses', 'roofs', 'concrete_roofs', 'wood_roofs']]

class House(object):pass
class Roof(object):pass
class ConcreteRoof(Roof):pass
class WoodRoof(Roof):pass

mapper(House, houses, properties={
     'roof':relation(Roof, uselist=False, cascade="all, delete-orphan", backref=backref("house"))
})

roof_union = polymorphic_union(
   {
      'concrete':concrete_roofs.join(roofs),
     'wood':wood_roofs.join(roofs),
   },
    None, 'roof_union'
)
mapper(Roof, roofs, select_table=roof_union, polymorphic_on=roofs.c.type)
mapper(ConcreteRoof, concrete_roofs, inherits=Roof, polymorphic_identity='concrete')
mapper(WoodRoof, wood_roofs, inherits=Roof, polymorphic_identity='wood')


...and if that all works (which it should.....) then we really have something cool going on here...


On Jun 16, 2006, at 7:43 AM, Koen Bok wrote:

Maybe a little metaphor to make it more simple.

Let's say I make houses. The roof of the house can either be concrete or wood. Concrete and wood come in many types.

Design:

House
id
name

Wood
id
name
treename

Concrete
id
name
hardness

Now if I have a House object it should have a roof relation which either links to a Wood object or a Concrete object. It NEEDS to be linked to one of them.

Like this:

>>> house = session.query(House).get(1)
>>> print house.roof
<Concrete id=123 name=SuperBeautiful hardness=500>

>>> house = session.query(House).get(2)
>>> print house.roof
< Wood id=321 name=Oak treename='Oak Tree'>


On 16-jun-2006, at 5:24, Michael Bayer wrote:

whats wrong with this ?

order_types
---------------
type_id
name
from_stock_id
to_stock_id

?

On Jun 15, 2006, at 6:44 PM, Koen Bok wrote:

Within my organisation we have orders. Orders move products between three entities: Suppliers, Stocks and Customers.

The type of an order gets defined by the origin and the destination it is moving products. This way we can have the following types of orders:

From: To: -> Stock BUYORDER
Stock -> Supplier RETOURBUYORDER
Stock -> Stock INTERNORDER
Stock -> Customer SELLORDER
Customer ! -> Stock RETOURSELLORDER

How can I design objects/mappers to do this:

>>> order = session.query(Order).get(1)
>>> print order.type
<Type id=123 name='INTERNORDER' from=<Stock id=2> to=<Stock id=4>>

>>> order = session.query(Order).get(2)
>>> print order.type
<Type id=456 name='SELLORDER' from=<Stock id=4> to=<Customer id=1928>>
_______________________________________________
Sqlalchemy-users mailing list



_______________________________________________
Sqlalchemy-users mailing list

_______________________________________________
Sqlalchemy-users mailing list

_______________________________________________
Sqlalchemy-users mailing list

_______________________________________________
Sqlalchemy-users mailing list

_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to