> > is it errorneus to explicitly put the (correct) joins even if they > > could be figured out by SA? > its not. but made your code that much harder to read well, this case does require them :-(
> > which has a way to interpret python functions into Expr-trees, which > > then can be translated (read code-generation) into whatever, like text > > or sql-alchemy column expressions. > are you using AST for this at least ? no need to reinvent the > wheel.... AST... i don't parse it, python parses it. i just replace .__eq__() with something else. The funny thing is, the python compiled code of some expression can be reinterpreted in diff.ways, e.g. def myfunc(x,y): return x>100 && y.startswith('big') .......... myfunc( 23, "big_balls_of_fire") - will eval the func yielding true/false, while myfunc( Var('x'), Var('y')) - will build you an expression (procided Var()s have operators etc defined). And even give errors - not any syntax will fit your new semantix. of course, theoretically, there is some AST, and some grammar, but it's sort-a virtual... > > It's all like using the python to build _your_ syntax tree made of your > > objects, and then use the objects - or some visitor - to do > > code-generation/ interpretation. > sounds awfully generic, when i could just write a little AST visitor... Each time a new grammar and AST and new visitor? and teach users to that new grammar? and testsuite preventing the huns into rome? mmh. i did that. couple of "languages" per year... Users (be them end-customers or the other-team) know their semantix pretty well and they can cope with just about any _sensible_ easy grammar as far as it speaks in their "lingo". oh well. my choice is - no more grammars (lowlevel) - if i can avoid them. > > As i said, think of activemapper that also does inheritance and > > queries, provided just a few hints of how user exactly wants it done. > as far as querying, im guessing you > are looking for an object-query-language (which is what all the "pure > ORM" types seem to be desiring...but strangely they never get....) not at all. SQL, OQL and probably all them *QL frighten me. Too extreme. Looks like academical creation with little touch to mortal people. i am targeting what u have with columns, but applied directly to object attributes, and used more for filtering, than real calculations. Practical stuff, as u said - whatever we can do, now. > > So, back to the question: inheritance and referencing together? > im in the business of maintaining and developing > SQLAlchemy, and if theres a bug which you can illustrate with a > *simple* test case of around 50 lines or less, ill fix the bug, 110. can't make it less ;-) can? and it is about A=Employee and B=Manager, and all Employees having a manager. http://linuxteam.sistechnology.com/orm/sa_B_inh_A_A_ref_AB2.py usage: 1) $ python sa_B_inh_A_A_ref_AB2.py Alink=Manager or 2) $ python sa_B_inh_A_A_ref_AB2.py Alink=Empluyee same 2 errors. if of any help, i've found that if no manager (reference) is being ever assigned, then case 1 does not crash. ------------- from sqlalchemy import * #table_inheritance, polymorphic def case( Alink='Manager' ): class Employee( object): name = '<notset>' def __str__(me): return ' '.join( [me.__class__.__name__, str(me.id), str(me.name), getattr( me.manager, 'name', '<none>') ]) class Manager( Employee ): bonus = '<notset>' def __str__(me): return Employee.__str__(me) + ' ' + str(me.bonus) db = create_engine( 'sqlite:///:memory:') meta = BoundMetaData( db) meta.engine.echo = 0 class tables: pass tables.Employee = Table('Employee', meta, Column('id', Integer, primary_key=True), Column('name', String, ), Column('atype', String), Column('manager_id', Integer, ForeignKey( Alink+'.id', use_alter=True, name='whatever1' ) ) ) tables.Manager = Table('Manager', meta, Column('bonus', String, ), Column('id', Integer, ForeignKey( 'Employee.id'), primary_key=True, ), ) meta.create_all() ajoin = { 'Employee': tables.Employee.select( tables.Employee.c.atype == 'Employee'), 'Manager': join( tables.Employee, tables.Manager, tables.Manager.c.id ==tables.Employee.c.id), } Ajoin = polymorphic_union( ajoin, None ) mA = mapper( Employee, tables.Employee, select_table=Ajoin, polymorphic_on=Ajoin.c.atype, polymorphic_identity='Employee' ) mA.add_property( 'manager', relation( Alink == 'Employee' and Employee or Manager, primaryjoin= tables.Employee.c.manager_id==(Alink=='Employee' and tables.Employee or tables.Manager).c.id, lazy=True, uselist=False, post_update=True ) ) mB = mapper( Manager, tables.Manager, polymorphic_identity='Manager', inherits = mA, inherit_condition = (tables.Employee.c.id == tables.Manager.c.id), ) #populate session = create_session() a = Employee() a.name = 'Dilberto' b = Manager() b.name = 'Boss' b.bonus = 'big' a.manager = (Alink == 'Employee' and a or b) session.save(a) session.save(b) session.flush() print a print b print list( tables.Employee.select().execute() ) print list( tables.Manager.select().execute() ) def test( klas, xid, xstr): one = session.query( klas).get_by_id( xid) x = str(one) r = 'single %(x)s ; expect: %(xstr)s' % locals() print '>>>>>', r assert x == xstr, r all = session.query( klas).select() x = '; '.join( str(z) for z in all ) r = 'multiple %(x)s ; expect[0]: %(xstr)s' % locals() print '>>>>>', r assert len(all) >= 1, 'size? '+ r assert str(all[0]) == xstr, r test( a.__class__, a.id, str(a)) test( b.__class__, b.id, str(b)) import sys kargs = dict( kv.split('=') for kv in sys.argv[1:]) case( **kargs) ============== --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---