Hello all, I'm running a different query than yesterday. Before, I had something like:
items = session.query(itemTable, attachmentTable, attachmentTextTable, assignmentTable, attributeTable, attributeValueTable, attributeValueAssignmentTable, vendorTable)\ .filter(attachmentTable.itm_id == itemTable.itm_id)\ #and so on, a bunch of .filter calls Then, in the loop iterating over the results, I could do this: for result in queryResults: itemID = result.item.itm_id Now that I'm using a bunch of outer left joins, that code is suddenly not working. I get an error when I say result.item.itm_id AttributeError: 'item' object has no attribute 'item' The problem is that my query starts out with only one table passed to session.query(), not all of them. Thus my result is of type 'item', which is the table passed in. That would be okay, except that I need to access values of other tables in the result, so even if I change id = result.item.itm_id to id = result.itm_id When I then say description = result.attach_text.att_value AttributeError: 'item' object has no attribute 'attach_text' I know why it doesn't. What I don't know is how to get my query results to hold all the information from all the tables, or how to access it if they do already, but in a different way than before. My new query is this: items = session.query(itemTable)\ .outerjoin(vendorTable, vendorTable.PVVNNO == itemTable.itm_vendornum)\ .outerjoin(assignmentTable, assignmentTable.itm_id == itemTable.itm_id)\ .filter(assignmentTable.att_id == attachmentTable.att_id)\ .outerjoin(attachmentTextTable, assignmentTable.att_id == attachmentTextTable.att_id)\ .outerjoin(attributeValueAssignmentTable, attributeValueAssignmentTable.itm_id == itemTable.itm_id)\ .outerjoin(attributeTable, attributeTable.attr_id == attributeValueAssignmentTable.attr_id)\ .filter(attributeValueTable.attr_value_id == attributeValueAssignmentTable.attr_value_id)\ .yield_per(1000) I've also tried the same query, but with the first line changed to: items = session.query(itemTable, attachmentTable, attachmentTextTable, assignmentTable, attributeTable, attributeValueTable, attributeValueAssignmentTable, vendorTable)\ The problem here is that, while result.item.* works as expected, other tables don't. For instance, result.attach_text.att_value yields an AttributeError, 'None' type object has no attribute att_value. Clearly, the other tables are in the result, but they're all None. I expected something like that, and only added them back in to see if it might help, but since I call query().outerjoin() I didn't think it would work. I should note that I renamed most of the tables by assigning variables to base.classes.tableName, which is why I'm using "itemTable" here, but in getting attributes of results I use just "item". The 'item' table is called 'item', but I assigned it to a variable called 'itemTable', just for clarity in the script. Is there a way to access the values of a query like this? At the very least, is there a way I can print out all the objects the result object has, so I can work out what to do? Thanks for any help! -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.