-
I am using ent for the first time and I really like the workflow and its privacy feature and gqlgen extension. I have a use-case where I want to display the records of one entity in a table, joined together with data that resides in a relational entity. The fact that this relational data resides partly in a JSON column doesn't make things easier (if not impossible at the time). Also, when it comes to (server-side) sorting, there is just no way that I found, that I could possibly use, to sort records according to an attribute of the child relation (using the gqlgen extension and GraphQL server, I forgot to say) So what I tried instead, was creating a VIEW in my DB schema and created an ent entity with matching fields and relations. And no surprise here: It works exactly as intended and makes sorting, filtering and pagination a breeze. However, there are two things that bother me here:
Thanks in advance |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
Hey @Coksnuss, // Using hooks:
func (T) Hooks() []ent.Hook {
return []ent.Hook{
hook.Reject(ent.OpCreate|ent.OpUpdate|ent.OpenUpdateOne||ent.OpDelete|ent.OpDeleteOne)
}
}
// Using privacy:
func (T) Policy() ent.Policy {
return privacy.Policy{
Mutation: privacy.MutationPolicy{
privacy.AlwaysDenyRule(),
},
Query: privacy.QueryPolicy{
// Allow any viewer to read anything.
privacy.AlwaysAllowRule(),
},
}
} |
Beta Was this translation helpful? Give feedback.
-
Hey @a8m , Thanks for the quick response and your suggestion with hooks & policies. I guess I won't need them for now, since I am the only developer on the project and I am aware of the fact that some entities are backed by a db view. Regarding migrations: I primarily rely on automatic migrations at the time. But I also already tried using versioned migrations with Altas. I am ready to use whatever tooling allows me to deal with the issue. When I tried Atlas, I couldn't get it to work either, because it also doesn't support views. If you have any advice, I am happy to hear it. Thanks! |
Beta Was this translation helpful? Give feedback.
-
i used context for check create or read only permissions...
in client:
|
Beta Was this translation helpful? Give feedback.
Hey @a8m ,
Thanks for the quick response and your suggestion with hooks & policies. I guess I won't need them for now, since I am the only developer on the project and I am aware of the fact that some entities are backed by a db view.
Regarding migrations: I primarily rely on automatic migrations at the time. But I also already tried using versioned migrations with Altas. I am ready to use whatever tooling allows me to deal with the issue. When I tried Atlas, I couldn't get it to work either, because it also doesn't support views. If you have any advice, I am happy to hear it. Thanks!