foreign-sapphire•3mo ago
Structure depeding on resources defined
having into consideration that each entity we define in our project is a resources for example students and school years the school has is it correct to define a resource called studentschoolyears that will allow us to access the relation of those two entities or should it be managed directly under student?
2 Replies
Hi @Lost Spartan. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
In Refine, each entity in your project (like students or school years) is typically defined as a separate resource. For relationships between entities—such as a many-to-many relationship between students and school years—it is common and correct to define an intermediate resource (e.g., studentschoolyears) to represent the association between them.
This approach aligns with how Refine handles many-to-many relationships. For example, in the documentation, a similar pattern is shown with products, categories, and an intermediate productCategories resource. The intermediate resource allows you to manage and fetch the relationships explicitly, and you can use hooks like useMany to retrieve related data for each entity as needed. This keeps your data structure clear and flexible, especially for CRUD operations on the relationship itself (e.g., enrolling a student in a school year or removing them) Many-to-Many Relationships.
So, defining a studentschoolyears resource is the recommended approach, rather than managing the relationship directly under student or school year resources. This also makes it easier to scale and maintain your application as relationships become more complex.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
<@244898948488101898> Kapa.ai is still learning and improving, please let me know how I did by reacting below.