Repository: fossasia/open-event-server

Issue:
Order relationship missing from Events
**I'm submitting a ...**  (check one with "x")
- [x] bug report
- [ ] feature request
- [ ] support request => Please do not submit support requests here, instead ask your query in out Gitter channel at https://gitter.im/fossasia/open-event-orga-server

**Current behavior:**
<!-- Describe how the bug manifests. -->
Orders have an event relationship but the events are missing an order relationship



Discussion:

Resolving patch:
diff --git a/app/api/__init__.py b/app/api/__init__.py
--- a/app/api/__init__.py
+++ b/app/api/__init__.py
@@ -157,7 +157,8 @@
           '/sessions/<int:session_id>/event', '/ticket-tags/<int:ticket_tag_id>/event',
           '/role-invites/<int:role_invite_id>/event', '/speakers/<int:speaker_id>/event',
           '/access-codes/<int:access_code_id>/event', '/email-notifications/<int:email_notification_id>/event',
-          '/attendees/<int:attendee_id>/event', '/custom-forms/<int:custom_form_id>/event')
+          '/attendees/<int:attendee_id>/event', '/custom-forms/<int:custom_form_id>/event',
+          '/orders/<order_identifier>/event')
 api.route(EventRelationship, 'event_ticket', '/events/<int:id>/relationships/tickets',
           '/events/<identifier>/relationships/tickets')
 api.route(EventRelationship, 'event_ticket_tag', '/events/<int:id>/relationships/ticket-tags',
@@ -200,6 +201,8 @@
           '/events/<identifier>/relationships/attendees')
 api.route(EventRelationship, 'event_custom_forms', '/events/<int:id>/relationships/custom-forms',
           '/events/<identifier>/relationships/custom-forms')
+api.route(EventRelationship, 'event_orders', '/events/<int:id>/relationships/orders',
+          '/events/<identifier>/relationships/orders')
 # Events -> roles:
 api.route(EventRelationship, 'event_organizers', '/events/<int:id>/relationships/organizers',
           '/events/<identifier>/relationships/organizers')
diff --git a/app/api/events.py b/app/api/events.py
--- a/app/api/events.py
+++ b/app/api/events.py
@@ -41,6 +41,7 @@
 from app.models.social_link import SocialLink
 from app.models.tax import Tax
 from app.models.event_copyright import EventCopyright
+from app.models.order import Order
 
 
 class EventSchema(Schema):
@@ -325,6 +326,13 @@ def validate_timezone(self, data, original_data):
                               schema='UserSchema',
                               type_='user',
                               many=True)
+    orders = Relationship(attribute='orders',
+                          self_view='v1.event_orders',
+                          self_view_kwargs={'id': '<id>'},
+                          related_view='v1.orders_list',
+                          schema='OrderSchema',
+                          type_='order',
+                          many=True)
 
 
 class EventList(ResourceList):
@@ -554,6 +562,13 @@ def before_get_object(self, view_kwargs):
             else:
                 view_kwargs['id'] = None
 
+        if view_kwargs.get('order_identifier') is not None:
+            order = safe_query(self, Order, 'identifier', view_kwargs['order_identifier'], 'order_identifier')
+            if order.event_id is not None:
+                view_kwargs['id'] = order.event_id
+            else:
+                view_kwargs['id'] = None
+
     def before_update_object(self, event, data, view_kwargs):
 
         if data.get('original_image_url') and data['original_image_url'] != event.original_image_url:


Test patch: