RE: newb: Correct way to set a SQLalchemy 'relation'
Hi Dalius, Thanks for getting back to me. Never seen it done this way. Even if it works it does not look correct way. It looks hard to understand and in some sense it is unpythonic - other developers will have hard time to understand it. Just look at pylons tutorials how it is done. I have checked the docs, and I can't find a specific example where a controller is explicitly trying to set a class attribute that is a foreign key: mapper(ArkClient, clients_table, properties={ 'contacts':relation(ArkContact, backref='client', cascade=all, delete), 'projects':relation(ArkProject, backref=backref('client'), cascade=all, delete, delete-orphan) }) Ie. Setting ArkClient.contacts or ArkCLient.projects As before, currently doing the following: contact.client=Session.query(ArkClient).filter(ArkClient.client=='clientName').first() The 'clientName' string is passed through via request.POST. If anyone has links to examples of how this is done better that would be much appreciated. Many thanks, Jules --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups pylons-discuss group. To post to this group, send email to pylons-discuss@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en -~--~~~~--~~--~--~---
Re: newb: Correct way to set a SQLalchemy 'relation'
contact.client=Session.query(ArkClient).filter(ArkClient.client=='clientName').first() I'd expect something like: contact.client=Session.query(ArkClient).filter(ArkClient.client.name=='clientName').first() I just find it very strange how you use SQLAlchemy: Table, class and mapper mixed into one class (ArkContact). While ArkClient mapper seems to be correct. As well it looks very strange that ArkClient has backref and you define client in ArkContact again and in addition with backref. It is enough to define this relation in one mapper. -- Dalius http://blog.sandbox.lt --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups pylons-discuss group. To post to this group, send email to pylons-discuss@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en -~--~~~~--~~--~--~---
RE: newb: Correct way to set a SQLalchemy 'relation'
Hey Dalius, contact.client=Session.query(ArkClient).filter(ArkClient.client=='clien tName').first() I'd expect something like: contact.client=Session.query(ArkClient).filter(ArkClient.client.name==' clientName').first() I just find it very strange how you use SQLAlchemy: Table, class and mapper mixed into one class (ArkContact). While ArkClient mapper seems to be correct. As well it looks very strange that ArkClient has backref and you define client in ArkContact again and in addition with backref. It is enough to define this relation in one mapper. Yes, apologies - I've changed from declarative to the more 'traditional' [separate table / class / mapper] route since my first post, I should have clarified that. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups pylons-discuss group. To post to this group, send email to pylons-discuss@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en -~--~~~~--~~--~--~---
Re: newb: Correct way to set a SQLalchemy 'relation'
Hi, contact=ArkContact() contact.client=Session.query(ArkClient).filter(ArkClient.client=='clientName ').first() Session.add(contact) Session.commit() This does seem to work, but I just wanted to know if this is the 'correct' way of doing things, it seems a little strange to me. Many thanks for any assistance. Never seen it done this way. Even if it works it does not look correct way. It looks hard to understand and in some sense it is unpythonic - other developers will have hard time to understand it. Just look at pylons tutorials how it is done. -- Dalius http://blog.sandbox.lt --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups pylons-discuss group. To post to this group, send email to pylons-discuss@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en -~--~~~~--~~--~--~---