how to model many-to-one relation using ezplatform?

37 Views Asked by At

project has lots of asset, an asset belongs to a group. then we have 3 content types

Project, ProjectAsset, AssetGroup

  1. store the assets relation in Project content type.

    Project

    name assets relation

    ProjectAsset

    image group relation

    Group

    name

with this approach, we need to upload project asset first, then add this relation to project.

  1. Store relation in ProjectAsset itself.

    Project

    name

    ProjectAsset

    image group relation project simple relation to project.

    Group

    name

with this approach, we specity relations(project, group relation) when we upload project asset.

what I want to do

  1. when delete project, the project asset should be deleted as well. does ezplatform support embed association like doctrine orm?

  2. when query project, I also need to get the project assets. what is the efficient way to do this? the query might be for a single project or a lists of project.

1

There are 1 best solutions below

0
On

Hi "out of the box" it's not possible but of course there is a solution for that. It requires some developpement though What I would do is add an EventListener (or EventSubscriber) plugged on specific object type deletion so it triggers the appropriate deletions of related objects.

https://symfony.com/doc/current/event_dispatcher.html