Comment 2 for bug 1704955

Revision history for this message
kaputtnik (franku) wrote :

The problem here is that there is no relation between build_costs and build_wares. The values get stored into the database in different fields:

    # Build cost
    build_wares = models.ManyToManyField(
        Ware, related_name='build_ware_for_buildings', blank=True)
    # ' '.joined() integer strings
    build_costs = models.CharField(max_length=100, blank=True)

Creating the relation between build_costs and build_wares is done in get_build_cost(). Retrieving build_wares is done through a query:

        for c, w in zip(count, self.build_wares.all()):
            yield [w] * c

and the query ( self.build_wares.all() ) returns the build_wares in a different order than stored in build_costs. So for atlantean Armor Smithy the result is: build_costs are '2 1 2 2' and the query returns: granite log planks quartz. The result is:

buildcost / query order
 2 / Granite
 1 / Log
 2 / Planks
 2 / Quartz

I currently don't know how to solve this. Since there is a possibility to get a default ordering of queries, we may have to make sure the values of build_costs are stored in the same order, say alphabetical depending on the name of ware? I think this would be just a workaround...