On Feb 9, 2008, at 12:33 PM, Leo wrote:

>
> I have the next mapper:
>
> mapper
> (DBBook
> ,outerjoin
> (books_table
> ,fulltext_table,books_table.c.id==fulltext_table.c.id),properties={
>        'id':[books_table.c.id,fulltext_table.c.id]
> })
>
> This row should return the books without fulltext
>
> book
> =db_session.query(DBBook).filter(DBBook.fulltext_body==null()).all()
>
> And it generates the next MySQL code:
>
> SELECT books.id AS books_id, books_fulltext.id AS books_fulltext_id,
> books.name AS books_name, books.author AS books_author,
> books.description AS books_description, books.publisher AS
> books_publisher, books.year AS books_year, books.pages AS books_pages,
> books.link AS books_link, books.md5 AS books_md5, books.section AS
> books_section, books_fulltext.fulltext_scanned AS
> books_fulltext_fulltext_scanned, books_fulltext.fulltext_body AS
> books_fulltext_fulltext_body
> FROM books LEFT OUTER JOIN books_fulltext ON books.id =
> books_fulltext.id
> WHERE books_fulltext.fulltext_body IS NULL ORDER BY books.id
>
> Running this query through PhpMyAdmin returns some results, but python
> code returns nothing! Is it a bug or not?
>
>>>>

SA will not return an instance if the row does not contain a full  
primary key.  For the outerjoin you're mapping to, the primary key  
would be the primary key column(s) of books_table + the primary key  
column(s) of fulltext_table.  Such as:

[books_table.c.id, fulltext_table.c.id]

You have to make the determination what the "primary key" of a  
particular row from your outerjoin should be.  If the books_table  
alone determines primary key, then you can add  
primary_key=[books_table.c.id] to your mapper.  If OTOH the  
combination of columns from both tables comprise the primary key, the  
mapper needs to be told that a composite primary key which may contain  
a NULL for one or more (but not all) of the columns is still a valid  
primary key, and for that you add the flag allow_null_pks=True to your  
mapper.

adding this to the FAQ since someone else had this question recently.






--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to