[sqlalchemy] How to write a self 2 self relationship?
I tried to write : # class User(Base): __tablename__ = 'users' id = Column(Integer, primary_key=True) name = Column(String) fullname = Column(String) password = Column(String) sons = relation(User, order_by=User.id, backref=parent) # But the as 'User' is not defined at the line ... relation ... is processed, the code above doesn't work. So, does sqlalchemy support self 2 self relationship ? If the answer is YES, how to do it? --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: How to write a self 2 self relationship?
put it as text, it will be eval()'uated later On Monday 16 February 2009 10:57:11 一首诗 wrote: I tried to write : #-- -- class User(Base): __tablename__ = 'users' id = Column(Integer, primary_key=True) name = Column(String) fullname = Column(String) password = Column(String) sons = relation(User, order_by=User.id, backref=parent) #-- -- But the as 'User' is not defined at the line ... relation ... is processed, the code above doesn't work. So, does sqlalchemy support self 2 self relationship ? If the answer is YES, how to do it? --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: How to write a self 2 self relationship?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 This is covered by the decl. layer documentation (including examples): - either use strings for the parameter or - you write outside the class scope User.sons = relation() - -aj On 16.02.2009 9:57 Uhr, 一首诗 wrote: I tried to write : # class User(Base): __tablename__ = 'users' id = Column(Integer, primary_key=True) name = Column(String) fullname = Column(String) password = Column(String) sons = relation(User, order_by=User.id, backref=parent) # But the as 'User' is not defined at the line ... relation ... is processed, the code above doesn't work. So, does sqlalchemy support self 2 self relationship ? If the answer is YES, how to do it? - -- ZOPYX Ltd. Co. KG - Charlottenstr. 37/1 - 72070 Tübingen - Germany Web: www.zopyx.com - Email: i...@zopyx.com - Phone +49 - 7071 - 793376 Registergericht: Amtsgericht Stuttgart, Handelsregister A 381535 Geschäftsführer/Gesellschafter: ZOPYX Limited, Birmingham, UK - E-Publishing, Python, Zope Plone development, Consulting -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkmZLQkACgkQCJIWIbr9KYxMRgCeODPG7oL4uj/HmmGinx9E1q3r xJsAoLq11zIMhRsSqLZfm2RwlLqWB6yA =ND9E -END PGP SIGNATURE- --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~--- begin:vcard fn:Andreas Jung n:Jung;Andreas org:ZOPYX Ltd. Co. KG adr;quoted-printable:;;Charlottenstr. 37/1;T=C3=BCbingen;;72070;Germany email;internet:i...@zopyx.com title:CEO tel;work:+49-7071-793376 tel;fax:+49-7071-7936840 tel;home:+49-7071-793257 x-mozilla-html:FALSE url:www.zopyx.com version:2.1 end:vcard
[sqlalchemy] Re: How to write a self 2 self relationship?
Like this ? class User(Base): __tablename__ = 'users' id = Column(Integer, primary_key=True) name = Column(String) fullname = Column(String) password = Column(String) sons = relation('User', order_by='User.id', backref=parent) I got an Exception: sqlalchemy.exc.ArgumentError: Could not determine join condition between parent/child tables on relation User.sons. Specify a 'primaryjoin' expression. If this is a many-to-many relation, 'secondaryjoin' is needed as well. On Feb 16, 5:08 pm, a...@svilendobrev.com wrote: put it as text, it will be eval()'uated later On Monday 16 February 2009 10:57:11 一首诗 wrote: I tried to write : #-- -- class User(Base): __tablename__ = 'users' id = Column(Integer, primary_key=True) name = Column(String) fullname = Column(String) password = Column(String) sons = relation(User, order_by=User.id, backref=parent) #-- -- But the as 'User' is not defined at the line ... relation ... is processed, the code above doesn't work. So, does sqlalchemy support self 2 self relationship ? If the answer is YES, how to do it? --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: How to write a self 2 self relationship?
thats diff. thing, see self-ref. relations http://www.sqlalchemy.org/docs/05/mappers.html#adjacency-list-relationships On Monday 16 February 2009 11:18:59 一首诗 wrote: Like this ? --- - class User(Base): __tablename__ = 'users' id = Column(Integer, primary_key=True) name = Column(String) fullname = Column(String) password = Column(String) sons = relation('User', order_by='User.id', backref=parent) --- - I got an Exception: sqlalchemy.exc.ArgumentError: Could not determine join condition between parent/child tables on relation User.sons. Specify a 'primaryjoin' expression. If this is a many-to-many relation, 'secondaryjoin' is needed as well. On Feb 16, 5:08 pm, a...@svilendobrev.com wrote: put it as text, it will be eval()'uated later --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: single table inheritance : query a subtype and its subtypes
Oh my mistake. It works totally! On 13 fév, 21:29, Michael Bayer mike...@zzzcomputing.com wrote: On Feb 13, 2009, at 12:05 PM, GustaV wrote: Hello! In a configuration looking like this: class Parent: pass class Child(Parent): pass class ChildChild(Child): pass I would like to query the Childs and all classes that inherits it (here: ChildChild), but not Parent instances. session.query(Child).all() returns Child type only ( SQL : WHERE type IN (2) ), and I'd like to avoid to manually list the classes that inherit Child class. query(Child) should be returning Child and ChildChild classes - the IN will include both subtypes. make sure you're not on an old version of sqlalchemy. --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Trac feed broken
It seems like there is some bad character in one of the ticket details as it's been a few days since I could access the Trac feed. My feed reader (liferea) complains of: XML Parsing Error: reference to invalid character number Location: file:/// Line Number 20, Column 14:pre | #x3; | ^ And it seems like it is rightfully complaining: http://feedvalidator.org/check.cgi?url=http%3A%2F%2Fwww.sqlalchemy.org%2Ftrac%2Ftimeline%3Fmilestone%3Don%26changeset%3Don%26ticket%3Don%26ticket_details%3Don%26wiki%3Don%26max%3D50%26daysback%3D90%26format%3Drss -- Gaëtan de Menten http://openhex.org --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: How to write a self 2 self relationship?
So, does sqlalchemy support self 2 self relationship ? If the answer is YES, how to do it? You may want to look at the remote_side keyword argument. http://www.sqlalchemy.org/docs/05/mappers.html#adjacency-list-relationships Regards, Alex --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: How to write a self 2 self relationship?
As I said in my previous mail, you really should look at the remote_side keyword argument in your relation. This is what it was done for and the paragraph adjacency-list-relationships from the documentation covers all you need to know to deal with self-referential relationships. Here's the link again: http://www.sqlalchemy.org/docs/05/mappers.html#adjacency-list-relationships Regards, Alex 2009/2/16 一首诗 newpt...@gmail.com: Like this ? class User(Base): __tablename__ = 'users' id = Column(Integer, primary_key=True) name = Column(String) fullname = Column(String) password = Column(String) sons = relation('User', order_by='User.id', backref=parent) I got an Exception: sqlalchemy.exc.ArgumentError: Could not determine join condition between parent/child tables on relation User.sons. Specify a 'primaryjoin' expression. If this is a many-to-many relation, 'secondaryjoin' is needed as well. On Feb 16, 5:08 pm, a...@svilendobrev.com wrote: put it as text, it will be eval()'uated later On Monday 16 February 2009 10:57:11 一首诗 wrote: I tried to write : #-- -- class User(Base): __tablename__ = 'users' id = Column(Integer, primary_key=True) name = Column(String) fullname = Column(String) password = Column(String) sons = relation(User, order_by=User.id, backref=parent) #-- -- But the as 'User' is not defined at the line ... relation ... is processed, the code above doesn't work. So, does sqlalchemy support self 2 self relationship ? If the answer is YES, how to do it? --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: A question about best practices after the Object Relational Tutorial
Thank you for your replies. With helper code I mean: I want the architecture of my program so: - There's a database - Only SQLAlchemy talks to the database - There is a function for every task that SQLAlchemy does So, I want to do something like this in the end: addCustomer (login='mylogin', password='secret', ...) and the function addCustomer checks input, creates a hash of the password and so on.. And that helper function then uses the SQLAlchemy API. I mean, I think you're all doing this too, since nobody wants to call the SQLalchemy API every time again and again. Thanks Jess --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] DataError inserting CURRVAL in an inline query with SQLAlchemy and SQLSoup
Hi all, I want to use the return value of a CURRVAL call as the value of a column in a row I'm inserting, to link together related records. I'm using Pylons with SQLAlchemy and SQLSoup. SQLAlchemy spits back at me a DataError because I'm trying to place CURRVAL in an integer field. How do I get the thing to reference the integer instead of taking my words as the literal field value? This is the error I receive from Pylons: class 'sqlalchemy.exc.DataError': (DataError) invalid input syntax for integer: CURRVAL('users_user_id_seq') 'INSERT INTO employees (employee_id, employee_user_id, employee_first_name, employee_last_name, employee_address, employee_city, employee_state, employee_zip, employee_extension) VALUES (%(employee_id)s, % (employee_user_id)s, %(employee_first_name)s, %(employee_last_name)s, % (employee_address)s, %(employee_city)s, %(employee_state)s, % (employee_zip)s, %(employee_extension)s)' {'employee_first_name': u'Jeff', 'employee_city': u'Olathe', 'employee_state': u'KS', 'employee_address': u'150', 'employee_id': 3L, 'employee_extension': u'1112', 'employee_user_id': 'CURRVAL(users_user_id_seq)', 'employee_zip': u'66062', 'employee_last_name': u'Poller'} Thanks in advance. : ) Signed Jeff --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: DataError inserting CURRVAL in an inline query with SQLAlchemy and SQLSoup
use func.currval(literal_column('users_user_id_seq')).though I'm not sure how SQLSoup is going to pass that in, its what *should* work. On Feb 16, 2009, at 7:03 PM, Jeff Cook wrote: Hi all, I want to use the return value of a CURRVAL call as the value of a column in a row I'm inserting, to link together related records. I'm using Pylons with SQLAlchemy and SQLSoup. SQLAlchemy spits back at me a DataError because I'm trying to place CURRVAL in an integer field. How do I get the thing to reference the integer instead of taking my words as the literal field value? This is the error I receive from Pylons: class 'sqlalchemy.exc.DataError': (DataError) invalid input syntax for integer: CURRVAL('users_user_id_seq') 'INSERT INTO employees (employee_id, employee_user_id, employee_first_name, employee_last_name, employee_address, employee_city, employee_state, employee_zip, employee_extension) VALUES (%(employee_id)s, % (employee_user_id)s, %(employee_first_name)s, % (employee_last_name)s, % (employee_address)s, %(employee_city)s, %(employee_state)s, % (employee_zip)s, %(employee_extension)s)' {'employee_first_name': u'Jeff', 'employee_city': u'Olathe', 'employee_state': u'KS', 'employee_address': u'150', 'employee_id': 3L, 'employee_extension': u'1112', 'employee_user_id': 'CURRVAL(users_user_id_seq)', 'employee_zip': u'66062', 'employee_last_name': u'Poller'} Thanks in advance. : ) Signed Jeff --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Trac feed broken
it says to me: Congratulations! [Valid RSS] This is a valid RSS feed. im not able to reproduce any issue in the straight FF reader. On Feb 16, 2009, at 6:54 AM, Gaetan de Menten wrote: It seems like there is some bad character in one of the ticket details as it's been a few days since I could access the Trac feed. My feed reader (liferea) complains of: XML Parsing Error: reference to invalid character number Location: file:/// Line Number 20, Column 14:pre | #x3; | ^ And it seems like it is rightfully complaining: http://feedvalidator.org/check.cgi?url=http%3A%2F%2Fwww.sqlalchemy.org%2Ftrac%2Ftimeline%3Fmilestone%3Don%26changeset%3Don%26ticket%3Don%26ticket_details%3Don%26wiki%3Don%26max%3D50%26daysback%3D90%26format%3Drss -- Gaëtan de Menten http://openhex.org --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: A question about best practices after the Object Relational Tutorial
I would put the addCustomer method on something other than the customer object, like the thing you're adding the customer to. Or bettery yet, you'd probably be just appending the customer. I think for your specific example, you should handle customer creation stuff (login + password) in __init__. class Customer(object): def __init__(self, login, secret): self.password = secret self.login = login # from Michael's example def _set_password(self, pw): self._password = sha1(pw) def _get_password(self): return self._password # other helper functions. def activate(self): self.status = 'a' def inactivate(self): self.status = 'i' def annoyOnThePhone(self): dialAsteriskAndAnnoy(self.phone_number) def sendMonthlyBill(self): # stuff pass customer = Customer('thelogin', 'thesecret') store.customers.append(customer) customer.activate() --Randall Jessica Meyer wrote: Thank you for your replies. With helper code I mean: I want the architecture of my program so: - There's a database - Only SQLAlchemy talks to the database - There is a function for every task that SQLAlchemy does So, I want to do something like this in the end: addCustomer (login='mylogin', password='secret', ...) and the function addCustomer checks input, creates a hash of the password and so on.. And that helper function then uses the SQLAlchemy API. I mean, I think you're all doing this too, since nobody wants to call the SQLalchemy API every time again and again. Thanks Jess --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: DataError inserting CURRVAL in an inline query with SQLAlchemy and SQLSoup
You cannot pass currval('users_user_id_seq') as a parameter value, you have to pass an integer value instead. I solved this problem in this way: INSERT INTO employees (employee_user_id, employee_id, employee_first_name, employee_last_name, employee_address, employee_city, employee_state, employee_zip, employee_extension) VALUES ( currval('users_user_id_seq'), %(employee_id)s, %(employee_first_name)s, %(employee_last_name)s, % (employee_address)s, %(employee_city)s, %(employee_state)s, % (employee_zip)s, %(employee_extension)s) % {'employee_first_name': u'Jeff', 'employee_city': u'Olathe', 'employee_state': u'KS', 'employee_address': u'150', 'employee_id': 3L, 'employee_extension': u'1112', 'employee_user_id': nextval('users_user_id_seq'), 'employee_zip': u'66062', 'employee_last_name': u'Poller' } j Jeff Cook wrote: Hi all, I want to use the return value of a CURRVAL call as the value of a column in a row I'm inserting, to link together related records. I'm using Pylons with SQLAlchemy and SQLSoup. SQLAlchemy spits back at me a DataError because I'm trying to place CURRVAL in an integer field. How do I get the thing to reference the integer instead of taking my words as the literal field value? This is the error I receive from Pylons: class 'sqlalchemy.exc.DataError': (DataError) invalid input syntax for integer: CURRVAL('users_user_id_seq') 'INSERT INTO employees (employee_id, employee_user_id, employee_first_name, employee_last_name, employee_address, employee_city, employee_state, employee_zip, employee_extension) VALUES (%(employee_id)s, % (employee_user_id)s, %(employee_first_name)s, %(employee_last_name)s, % (employee_address)s, %(employee_city)s, %(employee_state)s, % (employee_zip)s, %(employee_extension)s)' {'employee_first_name': u'Jeff', 'employee_city': u'Olathe', 'employee_state': u'KS', 'employee_address': u'150', 'employee_id': 3L, 'employee_extension': u'1112', 'employee_user_id': 'CURRVAL(users_user_id_seq)', 'employee_zip': u'66062', 'employee_last_name': u'Poller'} Thanks in advance. : ) Signed Jeff --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---