Today I learned: Primary and Secondary Joins

While developing my app I had to shape the data I get from the SQLAlchemy in a simplified way. Given models Client, Order, Receipt, where Order is referencing Client and Receipt is referencing Order I wanted to access in a view only relationship all receipts directly from the Client model. The way this is done is via primary and secondary joins.

class Client(Base):
    __tablename__ = "clients"

    id = Column(Integer, primary_key=True)
    name = Column(String)
    entity = Column(String)

    receipts = relationship("Receipt", secondary="orders", primaryjoin="Client.id==Order.client_id",secondaryjoin="Receipt.order_uuid==Order.uuid", viewonly=True)


class Order(Base):
    __tablename__ = "orders"

    uuid = Column(UUID(as_uuid=True), primary_key=True)
    client_id = Column(Integer, ForeignKey("clients.id", ondelete="CASCADE"))
    created = Column(DateTime)


class Receipt(Base):
    __tablename__ = "receipts"

    uuid = Column(UUID(as_uuid=True), primary_key=True)
    order_uuid = Column(UUID(as_uuid=True), ForeignKey("orders.uuid", ondelete="CASCADE"))
    created = Column(DateTime)

Of course such a relationship can only be read-only because in this case it would be impossible to preserve the references to allow an editable relationship.

So far, so good. Good luck!!!

Today I learned: Nginx, WordPress and Docker

So I decided to follow this guide to spawn a wordpress site. This is an awesome guide that uses Nginx, WordPress and Docker in a wonderful orchestration via Docker Compose. I started to have a weird issue with my themes. So images were not loaded, lack of various styling resources. I couldn’t understand where the issue came from. Then I realized that I mounted the themes folder in the docker-compose.yaml file in the following manner:

./themes:/var/www/html/wp-content/themes

The problem is that I shared the folder from the volume with the WordPress container yet not with the Nginx container! So don’t forget to share the folder with both containers so the webserver can serve the actual data! Good luck!!!