Many to one relationship

I need to represent this relationship: A project is associated to 0 or more maps. A map is associated to 0 or 1 project. When adding a new Map entry, I need to link it to a Project. When I open a project entry, I want to see all the linked Maps and add new links if needed.

This is exactly how Project/Tasks relationship works, but somehow, I can’t get it to work in my use case.

In “Project” doctype, I added a Table field linked to “Project Map”, a child table. “Project Map” has a Link field pointing to “Map”. “Map” has a link field poiting to “Project”.

I can add a new Map entry and select the linked project. When I open the corresponding Project entry, there is no Map entry in the child table. I have to manually select the linked Map(s).

However, in the Project/Task use case, I can create Task, link it to a Project, then open the Project and see the linked task I created.

What am I missing?

If I’m not mistaking, the project/Task is using 2-way syncronisation:
When a task is updated, the project is updated also: erpnext/ at 7d7e4534dd73d8b32f1661415fcec6fcf25fabfd · frappe/erpnext · GitHub
And when the Task (project.tasks/Project Task) changes, it’s also update the Task: erpnext/ at 6a7969117f1ec438f25ec5f8bfbbec10a04ef01d · frappe/erpnext · GitHub

So I think you just need to manually update from both side each time you make a change.
I know ERPNext is removing the Task in Project because it was a pain to have a two-way synchronisation

Ok I see. That’s quite an important and basic feature to remove though. Do you know if they will replace it with a better implementation?

I think, there’s a misunderstanding going on here.

@mel_erp is talking specifically about relations between Project and Task DocTypes.

As for your question, there is a one-to-many relationship implementation out of the box in Frappe (see Child Table docs), but to build many-to-many relationship, AFAIK you will need to implement some custom logic on the many side of the one-to-many relationship.

@igrekus So do I need to write some Python or this is already achievable using the web interface?

First of all, let me clarify a bit for us to be on the same ground. All of the following is based on my limited experience with Frappe, though I had the need for many-to-many relationship as well and was researching this subject.

AFAIK, there’s no build-in implementation of many-to-many relationship, available through the web interface in Frappe with the exception of the relationship between Project and Task DocTypes. That’s why you don’t see the desired behavior between Project/Project Map DocTypes.

The one you see in Project/Task relationship is build with custom logic, written within the custom scripts for Project and Task doctypes, designed to handle this specific relationship. @mel_erp is talking about this specific logic being removed in one of the updates.

If you want to implement this many-to-many relationship, you will need to write your own custom logic for the DocTypes you want to have this relationship for. This custom logic will need to be implemented in both JS and Python sides of your app.

It would be nice if the devs would confirm or disprove my reserch.

1 Like

This post could be useful

Any news on this?, I think it is a major concern to automatically fetch these relations.
Could it be done using “fetch from” ?