I've got the following models and I'd like to automatically filter out 
 ReservationPackages that contain a "soft deleted" package.  A package is 
"soft deleted" if deleted != null. I've been struggling with this for a few 
days now. The problem goes away if I don't use the proxy but then I cannot 
model duplicate packages on my reservation.


class ReservationPackage(db.Model):
    """    We must use the association pattern to support duplicate packages on 
a    reservation    """
    __tablename__ = "reservation_packages"

    id = db.Column(db.Integer, primary_key=True)
    reservation_id = db.Column(db.Integer, db.ForeignKey('reservations.id'))
    package_id = db.Column(db.Integer, db.ForeignKey('packages.id'))

    package = db.relationship("Package")

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

class Reservation(db.Model):
    """    Reservation represents a contract to rent something to a User    """
    __tablename__ = "reservations"

    id = db.Column(db.Integer, primary_key=True)

    # We unfortunately need to use an association like this to
    # support the ability to have duplicate packages.
    _package_rel = db.relationship(ReservationPackage, lazy="joined")

    packages = association_proxy('_package_rel', 'package')

class Package(db.Model):

  __tablename__ = "packages"

  id = db.Column(db.Integer, primary_key=True)
  deleted = db.Column(db.DateTime)




I could create a read only property that contains something like

return object_session(self).query(ReservationPackage) \
    .filter_by(reservation_id=self.id) \
    .join("package"). \
    filter(text("packages.deleted != null")).all()


but I'd really like to be able to manipulate the packages list through the 
packages property.



thanks,
-shawn

-- 
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 http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to