Reputation: 433
In my model design, there is no direct coorelation between Venues and Tickets. Venues is a 1-to-many relationship to Deals and Deals is a 1-to-many relationship to Tickets.
Venues -> Deals -> Tickets
This is probably a dumb question, but I want to have a Tickets.findByVenueId() operation. What is the most efficient way to query that and ensure it all happens on the server side? Do I need to have some kind of reference to a VenueId in the Ticket model?
I am using MongooseJS on Node.
Upvotes: 1
Views: 170
Reputation: 262494
I would definitely have a VenueId in each ticket. That is the only "sane" way to be able to query tickets by venue.
While that can be considered denormalization, you have to do this in NoSQL databases at times, and in this case, it is not a "troublesome" denormalization anyway, as there should never be any updates to that field (tickets don't change venues after they are issued), so there are no concerns about stale copies and data integrity.
Depending on your needs, you may even go so far as to include other venue data into the ticket (such as city name, or venue capacity) to facilitate more complex queries. Obviously this takes you further away from a "normalized" database, so apply only as needed. The first big line I would draw is at the point when these copied fields ever need to be updated, because that can get quite involved.
Upvotes: 1