Duplicate definition of column amount for Money embedded objects #5604

Closed
opened 2026-01-22 15:12:31 +01:00 by admin · 1 comment
Owner

Originally created by @mahbubkabir on GitHub (Jul 10, 2017).

Originally assigned to: @Ocramius on GitHub.

I've got a model with multiple Money properties; everything in the model shares a common currency (for example's sake, let's assume an Order model with amount and tax Money properties)

I'm using moneyphp/money to store money information and doctrine embeddables to store them. Mapping as below

    <embedded name="amount" class="Money\Money" use-column-prefix="false" />
    <embedded name="tax" class="Money\Money" use-column-prefix="false" />

And money embeddable as below

<embeddable name="Money\Money">
    <field name="amount" type="integer" nullable="true" column="amount" />
    <embedded name="currency" class="Money\Currency" use-column-prefix="false" />
</embeddable>

This db table already exists on production and cannot be changed. This money lib has two properties amount and currency. So when Doctrine tries to hydrate the embedded objects it complains about duplicate … Duplicate definition of column 'amount' on entity in a field or discriminator column mapping..

I understand, doctrine is stopping us from redeclaring the same property but Money lib/object will always have the same property(i.e. amount and currency). Is there any way to tell doctrine to reuse the same field name without using prefix?

Originally created by @mahbubkabir on GitHub (Jul 10, 2017). Originally assigned to: @Ocramius on GitHub. I've got a model with multiple Money properties; everything in the model shares a common currency (for example's sake, let's assume an Order model with amount and tax Money properties) I'm using **moneyphp/money** to store money information and doctrine embeddables to store them. Mapping as below <embedded name="amount" class="Money\Money" use-column-prefix="false" /> <embedded name="tax" class="Money\Money" use-column-prefix="false" /> And money embeddable as below <embeddable name="Money\Money"> <field name="amount" type="integer" nullable="true" column="amount" /> <embedded name="currency" class="Money\Currency" use-column-prefix="false" /> </embeddable> This db table already exists on production and cannot be changed. This money lib has two properties amount and currency. So when Doctrine tries to hydrate the embedded objects it complains about duplicate … `Duplicate definition of column 'amount' on entity in a field or discriminator column mapping.`. I understand, doctrine is stopping us from redeclaring the same property but Money lib/object will always have the same property(i.e. amount and currency). Is there any way to tell doctrine to reuse the same field name without using prefix?
admin added the InvalidQuestion labels 2026-01-22 15:12:31 +01:00
admin closed this issue 2026-01-22 15:12:32 +01:00
Author
Owner

@Ocramius commented on GitHub (Jul 12, 2017):

use-column-prefix="false" />

How is this supposed to work if both imports have no prefix? Of course the columns will collide...

Is there any way to tell doctrine to reuse the same field name without using prefix?

No, as this breaks the 1:1 mapping between entities and table definitions. I've seen this break in very unexpected ways in the past too.

This db table already exists on production and cannot be changed.

You can just duplicate the column

@Ocramius commented on GitHub (Jul 12, 2017): `use-column-prefix="false" />` How is this supposed to work if both imports have no prefix? Of course the columns will collide... > Is there any way to tell doctrine to reuse the same field name without using prefix? No, as this breaks the 1:1 mapping between entities and table definitions. I've seen this break in very unexpected ways in the past too. > This db table already exists on production and cannot be changed. You can just duplicate the column
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5604