What I'm doing, and sorry for not explaining further, is making a CSV file of data. Each row is a row in my results, or would be if I were just selecting from products. Having to select from attributes as well is where I'm having problems. Each product can have multiple attributes, and each attribute value can be assigned to multiple products. Joining everything (by using filter()) is giving me way too many results to deal with effectively.
Say we had a product with an ID of 001, a name of "widget", and an image of "images/001.jpg". This product has a weight and a color, but those attributes are in the attributevalues table. Attributes work something like this: attributeassignments has a product ID and an attribute ID. Attributes has an attribute ID and an attribute name ("color", "size", and so on). AttributeValues has an attribute ID and a value ("blue", "55", etc). For our widget, attributes might have 001, 001, "size"; 001, 002, "color"; 001, 003, "weight". 001 is the product ID of the widget. AttributeAssignment might have 001, 001; 001, 002; 001, 003. 001 is the widget, and the second numbers are the IDs of the different attributes. AttributeValues might have 001, "1x2x3"; 002, "blue"; 003, "55". In the CSV file, I want to put each of those three attributes under a column: 001, Widget, images/001.jpg, blue, 55, 1x2x3 Currently, I'm iterating over the results. The first line inside the loop, I check the current result's ID and compare it to the previous one. If they match, I assume I'm on the same result, so I get the values of the attributes in the row. If the two IDs differ, I assume I'm done. I write out the values for the last result, clear out the array I use to store all the values, and grab the new values that aren't attributes. My current query does so much joining that my results are too large to manage, though. The very first iteration works perfectly, but then I get stuck with the same product ID number. Even when I raise the query limit to 100,000, I never see any other product ID than that first one. It feels like an infinite loop, but my loop is simply, items = <my query> for result in items: ... I hope this makes more sense. I've re-read the ORM tutorial as Jonathan suggested, too. The last bit, about many-to-many relationships, seems like it might be useful. I don't quite follow it all, but hopefully some of it will make more sense the more I re-read it. On 3/10/16, Jonathan Vanasco <jonat...@findmeon.com> wrote: > 2 comments: > > 1. Go through the SqlAlchemy ORM tutorial. What you're describing right > now is dancing around some very basic relationship definition and > loading/query techniques. > > 2. You haven't described what you actually want to accomplish, only some > general ideas of how you think you could interact with data. If you want > to grab a matrix that has every product, there will be one set of ways to > approach the problem. If you want to return an iterable list of all > variations of a certain product, there will be another set of ways. If you > > want to search by specific criteria, there will be yet another set of ways. > > depending on what you do with the data, the query will be different. > > > > > > -- > 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. > -- 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.