Skip to content
Snippets Groups Projects
Verified Commit 7bbb6d95 authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Fix master_waypoint relationship.

Thanks to @mirabilos!
parent ab8ec229
No related branches found
No related tags found
No related merge requests found
...@@ -62,7 +62,10 @@ class Waypoint(Base): ...@@ -62,7 +62,10 @@ class Waypoint(Base):
longitude = Column(Float) longitude = Column(Float)
listing_id = Column(Integer, ForeignKey('listings.id')) listing_id = Column(Integer, ForeignKey('listings.id'))
listing = relationship('Listing', back_populates='waypoints') listing = relationship('Listing', back_populates='waypoints', primaryjoin='Waypoint.listing_id == Listing.id')
master_of_id = Column(Integer, ForeignKey('listings.id'))
master_of = relationship('Listing', back_populates='master_waypoint', primaryjoin='Waypoint.master_of_id == Listing.id')
@property @property
def platform_prefix(self): def platform_prefix(self):
...@@ -83,8 +86,8 @@ class Listing(Base): ...@@ -83,8 +86,8 @@ class Listing(Base):
description = Column(String) description = Column(String)
hints = Column(String) hints = Column(String)
master_waypoint_code = Column(String) master_waypoint = relationship('Waypoint', uselist=False, primaryjoin='Waypoint.master_of_id == Listing.id')
waypoints = relationship('Waypoint', back_populates='listing') waypoints = relationship('Waypoint', back_populates='listing', primaryjoin='Waypoint.listing_id == Listing.id')
logs = relationship('Log', back_populates='listing') logs = relationship('Log', back_populates='listing')
...@@ -94,16 +97,6 @@ class Listing(Base): ...@@ -94,16 +97,6 @@ class Listing(Base):
owner_account_id = Column(Integer, ForeignKey('geocacher_accounts.id')) owner_account_id = Column(Integer, ForeignKey('geocacher_accounts.id'))
owner_account = relationship('GeocacherAccount', back_populates='listings') owner_account = relationship('GeocacherAccount', back_populates='listings')
# FIXME use proper relationship
@property
def master_waypoint(self):
for wp in self.waypoints:
if wp.code == self.master_waypoint_code:
return wp
@master_waypoint.setter
def master_waypoint(self, wp):
self.master_waypoint_code = wp.code
@property @property
def code(self): def code(self):
return self.master_waypoint.code return self.master_waypoint.code
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment