[sqlalchemy] Re: FlushError (unsaved, pending instance and is an orphan)
what's your mappers? many2one/one2many relations etc? I expected that I can create a parent-child link either from parent to child (by appending to ranker.results) or from child to parent (as above), but apparently the latter doesn't seem to work. Is this the case or something else is wrong ? George --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: association obj/proxy
seems this is the month of the many2many relations ;-) more on the theme: many2many i have a association of 3 tables, A,B,C. one of them (C) may not be present in all assoc_items. So that column has nullable=True. The problem is: adding associations to A-objects and saving them works; but retrieving omits those records which do not have 3rd item. The generated sql query is ok, executing it manualy gives proper results. is there some additional logic/filtering in the relation (in Instrumentedlist/loader) that does this, or am i missing something, or this is bug (and u want a testcase) ? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: FlushError (unsaved, pending instance and is an orphan)
On Apr 6, 2:52 am, svilen [EMAIL PROTECTED] wrote: what's your mappers? many2one/one2many relations etc? I expected that I can create a parent-child link either from parent to child (by appending to ranker.results) or from child to parent (as above), but apparently the latter doesn't seem to work. Is this the case or something else is wrong ? George It's one2many from Ranker to Result. class Ranker(Entity): has_many('results', of_kind='Result', cascade='all, delete- orphan') # (...) other fields class Result(Entity): belongs_to('ranker', of_kind='Ranker', column_kwargs=dict(nullable=False)) # (...) other fields George --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: FlushError (unsaved, pending instance and is an orphan)
On 4/6/07, George Sakkis [EMAIL PROTECTED] wrote: I'm using SA (with Elixir on top) and I have a parent Entity Ranker that has many children Results; that is, for a Ranker instance rk, rk.results gives its children and for a Result rs, rs.ranker gives its parent. When I add new children by providing the parent to the constructor of the child (rather than appending the child to rk.results) and then try to flush, I get: FlushError: instance Result at (...) is an unsaved, pending instance and is an orphan (is not attached to any parent 'Ranker' instance via that classes' 'results' attribute) Here's a (very) stripped-down version of what I'm doing: ranker = Ranker(...) for score in scores: Result(ranker=ranker, score=score, **kwds).save() session.flush() You shouldn't use .save() on your result instances because Elixir automatically adds new instances of your mapped classes to the thread's session. Or more precisely, Elixir uses the assign_mapper plugin which in turns uses the SessionContextExt mapper extension which does that. And session.flush() looks suspicious too. In Elixir, you usually either flush all pending objects using objectstore.flush() or single instances using instance.flush() I expected that I can create a parent-child link either from parent to child (by appending to ranker.results) or from child to parent (as above), but apparently the latter doesn't seem to work. Is this the case or something else is wrong ? George -- 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: association obj/proxy
On Apr 6, 2007, at 5:39 AM, svilen wrote: seems this is the month of the many2many relations ;-) more on the theme: many2many i have a association of 3 tables, A,B,C. one of them (C) may not be present in all assoc_items. So that column has nullable=True. The problem is: adding associations to A-objects and saving them works; but retrieving omits those records which do not have 3rd item. The generated sql query is ok, executing it manualy gives proper results. is there some additional logic/filtering in the relation (in Instrumentedlist/loader) that does this, or am i missing something, or this is bug (and u want a testcase) ? when you say, association of 3 tables, A,B, C, do you mean, there is a table D that contains a reference to all of A, B, C ? if thats the case, and D's reference columns to A, B, and C comprise a primary key, SA's default behavior when it sees a composite primary key of 3, 4, NULL is to determine that the row does not represent an entity. use the flag allow_null_pks=True on your mapper() to have such a primary key be counted. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] adding joins to existing select
Hi, is there are any way to add additional joins to a given select object? My problem is the following, I need to join the same table multiple times. How many times I don't know in advance and in addition I need to apply where clause while adding this join. Thanks, Valentin. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: adding joins to existing select
the select object supports an append_from() method. however, if you want to chain the joins themselves together, you probably want to construct the Join object ahead of time and add it to the select via append_from() (or create the select by calling the select() method off the Join itself) once its complete. On Apr 6, 2007, at 3:52 PM, vkuznet wrote: Hi, is there are any way to add additional joins to a given select object? My problem is the following, I need to join the same table multiple times. How many times I don't know in advance and in addition I need to apply where clause while adding this join. Thanks, Valentin. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: association obj/proxy
seems this is the month of the many2many relations ;-) more on the theme: many2many i have a association of 3 tables, A,B,C. one of them (C) may not be present in all assoc_items. So that column has nullable=True. when you say, association of 3 tables, A,B, C, do you mean, there is a table D that contains a reference to all of A, B, C ? if thats the case, and D's reference columns to A, B, and C comprise a primary key, SA's default behavior when it sees a composite primary key of 3, 4, NULL is to determine that the row does not represent an entity. use the flag allow_null_pks=True on your mapper() to have such a primary key be counted. yes, thanks, that's it. btw whats the reasoning/rational behind the above default behaviour? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: association obj/proxy
On Apr 6, 2007, at 8:19 PM, [EMAIL PROTECTED] wrote: btw whats the reasoning/rational behind the above default behaviour? i think it is often unexpected behavior, particularly for a query that returns rows between say table A and table B, where some of the rows contain nulls for the B columns. if the primary key is composite between A and B, distinct entities get created twice for each A row, one corresponding to the B columns present, one corresponding to the B columns not present. we have one polymorphic test that fails with this option turned on - test/orm/ inheritance3.py. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---