Hey there, thanks for reading this Q&A and trying to help!
Currently trying to develop a Fleet/Event Management application. For this there exists some domain entities which I am unsure how to properly model.
Basically there is an entity called "Event" and an "Order". An events contains e.g. an title, a short description about the event etc. Orders on the other hand contain information about what items are needed for that event and combines these items with a specific car.
So I have a relationship between an Event, which can contain many orders, and the other way around (an Order is related to an event).
I used Appwrite relationships to realize this (one-to-many, bidirectional). When fetching an Event, I get a list of bookings but obviously the "event" property of these bookings is not present/null. And the other way around - when fetching an order, the event's bookings dont contain the fetched order. From database/api level this make sense because otherwise we would have an endless loop but how should I define my models then?
class Order with _$Order {
const Order._();
/// Default constructor for a new order.
const factory Order({
/// The unique identifier of the order.
@JsonKey(name: "\$id", includeToJson: false) String? id,
/// The status of the order.
@Default(OrderStatus.pending) OrderStatus status,
/// The event the order is for.
required Event event,
/// The list of items in the order.
@Default([]) List<OrderItem> items,
/// The messages regarding the order.
@Default([]) List<OrderMessage> messages,
/// The date when the order is scheduled to be loaded.
DateTime? scheduledLoadingDate,
/// The date when the order is scheduled to be offloaded.
DateTime? scheduledOffloadDate,
}) = _Order;
/// .....
}
@freezed
class Event with _$Event {
const Event._();
factory Event({
/// The unique identifier of the event.
String? id,
/// The title of the event.
@Default("") String title,
/// The description of the event.
@Default("") String description,
/// The start date of the event.
required DateTime start,
/// The end date of the event.
required DateTime end,
/// The list of orders for the event.
@Default([]) List<Order> orders,
}) = _Event;
/// .....
}
The problem is now that when fetching an Event, the fromJson is called of the Order Model to parse it but since the order is fetched as part of the event, its the orders' event property is missing and this leads to a parsing error.
Should i just make the "event" property nullable or is there a better way?
Recommended threads
- Realtime api and labels as permission
in my tables i set labels as permission and real-time capabilities stopped working. Before when i was having "any" role everything was working. Note: user have...
- Sveltekit + Bun sites runtime not deploy...
anyone tried deploying sveltekit + bun sites? its building but not running, and the only thing from build console to value is ``` > Using svelte-adapter-bun .s...
- Domain is owned by a different organizat...
I was trying to add a domain to one of my projects however, it keeps giving me the error of Domain is owned by a different organization. I did have a self hoste...