Thanks, Eric.
I messed around with the memento settings. adding includes = [ "product.name", "product.price" ]
still returns the entire product
model unless I ignoreDefaults=true
Overriding defaults works, but I have to manually specify everything in the Cart
model from scratch, which is not ideal.
My current thinking (I need to test it) is that this is a case for setting up dynamic mementifier profiles within the model. So I can do something like this for various API endpoints:
// index
asMemento( profile="simple" );
// new
asMemento( profile="new" );
// show
asMemento( profile="full" );
I’m torn on the idea of offloading memento rules into the model layer, since that feels more like a handler concern to me… but I suppose I could go either way on that.
This is a bit off-topic, but I kept encountering the guardAgainstNotLoaded()
error when testing various memento patterns with new, unpersisted, entities with Quick. Bypassing the guard doesn’t work in Quick 5 due to some changes in how relationships work. I created a PR to address the issue with the exception being thrown: Fix Required Parameter Error When Null by homestar9 · Pull Request #209 · coldbox-modules/quick · GitHub
As an added benefit , the above PR fix combined with disabling the loaded guard, should allow developers to use the null object pattern by specifying memento defaults when a relationship is null like this:
// inside a Quick entity
private void function setUpMementifier() {
super.setupMementifier();
this.memento.defaults = {
"product": {}
};
}