2 ms·
> One way to avoid the problem is to remember to pass the ticket object from the collection to the model and not instantiate a new one. My initial thought exac
by crescentfresh 15y ago
> One way to avoid the problem is to remember to pass the ticket object from the collection to the model and not instantiate a new one.
My initial thought exactly.
> However, as your app grows complex, you will not be able to keep a track of all the places where an object with a particular id is being initialized.
That's a bit vague. Why not?
This seems not much more than trying to standardize a global registry lookup for your models. Why not just make your collection globally accessible, and reference the fetched model with
$app.tickets.get(id)
?
- prateekdayal 15y ago> This seems not much more than trying to standardize a global registry lookup for your models. Why not just make your collection globally accessible, and reference the fetched model with Because the collection could be inside another object. Also there would be other places in the app where ticket models are being initialized. By defining/having to refer to global variables, you are just writing code that is harder to maintain. The identity map approach is more like Rails where in a single request, the same SQL does not hit the db again and just returns the pre-fetched results. You don't have to think about where else you are fetching the same records ever.
- prateekdayal 15y agoAlso a ticket could be present in two different collections fetched from different urls. For example, the same ticket could be in /tickets/all_tickets and /tickets/my_tickets. The book keeping just keeps getting harder as your app grows