I'm not entirely sure if it would fit here but since you're memoizing `@materialized` and then materializing its relation based on that ivar then maybe it would be better to have `Variable::Materialized < Variable` that would simply override `mutate_relation`, call super and materialise the relation just like `Variable` does now but without the need to check `@materialized` "flag"?

It's an extra class to be added but I find this approach better in such cases as it's more explicit and I have objects responsible for certain things with behaviour that doesn't rely on some special conditions (like `@materialized` here).