cosmicpython / code

Example application code for the python architecture book
Other
2.07k stars 926 forks source link

A question on SqlAlchemyRepository in chapter 6 #8

Open haibin opened 4 years ago

haibin commented 4 years ago

I see the below code for chapter 6. I'm wondering why we do .first(). Shouldn't we sort by version_number and get the latest Product?

class SqlAlchemyRepository(AbstractRepository):

    def __init__(self, session):
        self.session = session

    def add(self, product):
        self.session.add(product)

    def get(self, sku):
        return self.session.query(model.Product).filter_by(sku=sku).first()
hjwp commented 4 years ago

good question! there should only ever be one Product for a given sku tho. We're not storing each version as a separate row, just incrementing the version number within a given row...

hjwp commented 4 years ago

will see if i can clarify that somehow. incidentally, for issues relating to the book rather than the code, maybe put them in this repo? https://github.com/cosmicpython/book

thanks very much for sending in your questions, we really, really appreciate them. it's nice to know someone is paying attention!