Skip to content

Support to revert inversedBy/mappedBy in JoinColumn to add foreign key to "mapped" table (OneToOne association) #11941

Open
@WinterSilence

Description

@WinterSilence

Feature Request

What

Support to revert inversedBy/mappedBy in JoinColumn to add foreign key to "mapped" table (OneToOne association).

Why

Real case: I have meta_data table related to products, categories and etc. with FK like as

FOREIGN KEY (`id`) REFERENCES `products` (`meta_data_id`) ON DELETE CASCADE

In this case, if I remove product/category, then also remove attached record in meta_data.
But I can't create same FK by Doctrine, because FK adds to products and I can't change this behavior.

How

Switch inversedBy/mappedBy to add foreign key to meta_data table, instead products:

#[ORM\Entity]
#[ORM\Table(name: 'products')]
class Product
{
    // now support only set inversedBy
    #[ORM\OneToOne(targetEntity: MetaData::class, mappedBy: 'product')]
    #[ORM\JoinColumn(name: 'meta_data_id')]
    private MetaData $metaData;
}

#[ORM\Entity]
#[ORM\Table(name: 'meta_data')]
class MetaData
{
    // now support only set mappedBy
    #[ORM\OneToOne(targetEntity: Product::class, inversedBy: 'metaData')]
    private Product $product;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions