[sqlalchemy] Re: Mapper bug involving select with labeled foreign key target and clause default?

2007-10-28 Thread Brian Beck

Thanks for the response Mike... comments below.

On Oct 28, 12:52 am, Michael Bayer [EMAIL PROTECTED] wrote:
 On Oct 27, 2007, at 8:33 PM, Brian Beck wrote:
 without trying it yet the first thing that seems wrong is that your
 select has no join condition between a_table and b_table (nor are you
 using a join(), which would figure it out for you based on foreign
 keys, so your foreign key doesn't impact the equation much here on
 the select side).  the select will return the cartesian product
 between a and b which is definitely not what you want.

Doesn't matter -- same thing happens with or without the join
condition. (The cartesian product was intentional.)

 the actual error seems that the b_id column is tripping off a refresh
 of the instance's row, but when it issues your select(), its still
 not getting back what it wants.  since the mapper seems confused by
 the primary key of the select (which is likely because you have a_id
 represented twice), you might want to look into setting up your
 'the_id_of_a' property at the mapper level as a synonym() or
 column_property() attribute. I dont see what good it does embedded
 into that select().  or, try explicitly setting the mapper's
 primary_key attribute to the desired columns from your select().

Pretend the Select is more complicated and needs to reference both IDs
(which may have come from subqueries) -- in this case any mapper
features (like synonym) don't help, the Select needs to exist first!

Isn't it an error that b_id trips off a refresh?  The correct values
are inserted and should be available in last_inserted_ids for the
mapper to populate instance with...


--~--~-~--~~~---~--~~
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: Mapper bug involving select with labeled foreign key target and clause default?

2007-10-28 Thread Michael Bayer


On Oct 28, 2007, at 4:32 PM, Brian Beck wrote:

 Pretend the Select is more complicated and needs to reference both IDs
 (which may have come from subqueries) -- in this case any mapper
 features (like synonym) don't help, the Select needs to exist first!

the select can reference whatever columns it wishes in its WHERE  
clause, ORDER BY clause, whereever, *without* them being in the  
columns clause...your columns clause need not reference any columns  
whatsoever and it can still locate the correct rows.   so you should  
be putting only unique columns in the columns clause of your  
SELECT.or, if youd like to tell your mapper about both columns  
being the same, set up the mapping like this:

ab_mapper = mapper(AB, s, properties={
 'id':[s.c.a_id, s.c.the_id_of_a]
})

then the class has a single 'id' attribute mapped to both columns.



 Isn't it an error that b_id trips off a refresh?  The correct values
 are inserted and should be available in last_inserted_ids for the
 mapper to populate instance with...

this is a slight issue in that its seeing the inline SQL as a  
postfetch trigger when its not, so that is fixed in r3679.


--~--~-~--~~~---~--~~
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: Mapper bug involving select with labeled foreign key target and clause default?

2007-10-27 Thread Michael Bayer


On Oct 27, 2007, at 8:33 PM, Brian Beck wrote:


 Sorry for the confusing subject.  If I map against a select in which
 one of the tables has a foreign key whose default value is set to a
 clause involving another table's column (also in the select), and that
 column is labeled, the correct values are inserted, but an exception
 is raised when accessing the foreign key attribute on the instance
 (the instance is in an invalid state).

without trying it yet the first thing that seems wrong is that your  
select has no join condition between a_table and b_table (nor are you  
using a join(), which would figure it out for you based on foreign  
keys, so your foreign key doesn't impact the equation much here on  
the select side).  the select will return the cartesian product  
between a and b which is definitely not what you want.

the actual error seems that the b_id column is tripping off a refresh  
of the instance's row, but when it issues your select(), its still  
not getting back what it wants.  since the mapper seems confused by  
the primary key of the select (which is likely because you have a_id  
represented twice), you might want to look into setting up your  
'the_id_of_a' property at the mapper level as a synonym() or  
column_property() attribute. I dont see what good it does embedded  
into that select().  or, try explicitly setting the mapper's  
primary_key attribute to the desired columns from your select().

just some things to try. 

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---