Open lolopinto opened 3 years ago
https://github.com/lolopinto/ent/pull/506 and https://github.com/lolopinto/ent/pull/508
need full polymorphic edge support in the future
+1 on this issue.
I would love to see this implemented! It seems that this is required to model the following - or is there an alternative?
What I would like to model:
User
and Bot
SchemasAccount
objects. Account
must be owned by exactly one User
or Bot
(making the "owner" polymorphic)Is it possible to model this with the current capabilities?
Alternatively, should the PolymorphicOptions.types
perhaps allow to reference a Pattern
, such as AccountOwner
, instead of a (list of) Schema
?
you can kinda do this with patterns
I just checked in an example:
used by Account
/Workspace
:
https://github.com/lolopinto/ent/blob/c02c679fdab2d4f56967add1c81bd5b35b84b30e/examples/todo-sqlite/src/schema/account_schema.ts#L9
and in a trigger, set the edge https://github.com/lolopinto/ent/blob/c02c679fdab2d4f56967add1c81bd5b35b84b30e/examples/todo-sqlite/src/ent/todo/actions/create_todo_action.ts#L20-L25
downsides:
in your case:
export class AccountContainer implements Pattern {
name = "account_container";
fields: {};
edges: Edge[] = [
{
name: "accountsOwned",
schemaName: "Account",
inverseEdge: { name: "accountOwner" },
},
];
}
const UserSchema = new EntSchema({
patterns: [new AccountContainer()],
// ...
});
export default UserSchema;
const BotSchema = new EntSchema({
patterns: [new AccountContainer()],
// ...
});
export default BotSchema;
Is this fixed?
e.g. an edge that's shared across different types
probably implemented with pattern support in edges and a way to reuse the same edge across things