Skip to content

Conversation

@cedricziel
Copy link
Contributor

This change skips the creation of mapped fields inside embeddables.

Consider the PHP Money class:

public class Invoice {
  /**
   * @var Money
   *
   * @ORM\Embedded(class="Money\Money")
   */
  private $total;
}
final class Money implements \JsonSerializable {
   /**
    * @var Currency
    */
   private $currency;
}

Here, Money has the mapped field Currency. In doctrine Metadata,
this is correctly reflected as total.currency.

The EntityRegenerator declares a private field $total.currency afterwards.

The changeset suppresses this behaviour by skipping fields containing a
dot as is done a few lines below.

@weaverryan
Copy link
Member

Hey @cedricziel!

This is an excellent change! But could you add a test for it? There are a lot of test cases already in the FunctionalTest class - we just need to duplicate an existing one, use an embeddable, and make sure the generated code doesn't explode (because a property named $total.currency will definitely make things explode).

Thanks!

This change skips the creation of mapped fields inside embeddables.

Consider the PHP Money class:

```php
public class Invoice {
  /**
   * @var Money
   *
   * @Orm\Embedded(class="Money\Money")
   */
  private $total;
}
```

```php
final class Money implements \JsonSerializable {
   /**
    * @var Currency
    */
   private $currency;
}
```

Here, Money has the mapped field `Currency`. In doctrine Metadata,
this is correctly reflected as `total.currency`.

The EntityRegenerator declares a private field `$total.currency` afterwards.

The changeset suppresses this behaviour by skipping fields containing a
dot as is done a few lines below.
@weaverryan
Copy link
Member

Thank you Cedric!

@weaverryan weaverryan merged commit a4d4787 into symfony:master Mar 1, 2019
weaverryan added a commit that referenced this pull request Mar 1, 2019
This PR was squashed before being merged into the 1.0-dev branch (closes #316).

Discussion
----------

Skip embedded fields in embeddables

This change skips the creation of mapped fields inside embeddables.

Consider the PHP Money class:

```php
public class Invoice {
  /**
   * @var Money
   *
   * @Orm\Embedded(class="Money\Money")
   */
  private $total;
}
```

```php
final class Money implements \JsonSerializable {
   /**
    * @var Currency
    */
   private $currency;
}
```

Here, Money has the mapped field `Currency`. In doctrine Metadata,
this is correctly reflected as `total.currency`.

The EntityRegenerator declares a private field `$total.currency` afterwards.

The changeset suppresses this behaviour by skipping fields containing a
dot as is done a few lines below.

Commits
-------

a4d4787 Embed money objects
074f836 Remove double slash
6b9f7d8 Map embeddable money test with XML for convenience
84e2f58 Add small test to embeddable test
5c48add Skip embedded fields in embeddables
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants