<p dir="auto">Im not sure if this is an implementation issue or Doctrine itself. But if i was to create two identical entities and persist them, why does doctrine store two entries in the database? surely the idea of a DBAL is to handle normalisation for you? Is there a way you can prevent duplicate entries in the database?</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="        $address = new Address();
        $address-&gt;setTitle('Mr');
        $address-&gt;setFirstname('Sam');
        $this-&gt;em-&gt;persist($address);

        $address1 = new Address();
        $address1-&gt;setTitle('Mr');
        $address1-&gt;setFirstname('Sam');
        $this-&gt;em-&gt;persist($address1);"><pre class="notranslate"><code class="notranslate">        $address = new Address();
        $address-&gt;setTitle('Mr');
        $address-&gt;setFirstname('Sam');
        $this-&gt;em-&gt;persist($address);

        $address1 = new Address();
        $address1-&gt;setTitle('Mr');
        $address1-&gt;setFirstname('Sam');
        $this-&gt;em-&gt;persist($address1);
</code></pre></div>
<p dir="auto">I feel doctrine should not persist the second entity but just pretend it has. It should then only create two rows if the two entities where to become different.</p>
<p dir="auto">The Framework bundle only implements two asset version strategies: empty and static (defaults provided by the Asset component).</p>
<p dir="auto">If I want to use a custom strategy for my package (eg. to add the locale its path) without overriding the defaults, the <a href="https://github.com/symfony/symfony-docs/pull/4987" data-hovercard-type="pull_request" data-hovercard-url="/symfony/symfony-docs/pull/4987/hovercard">recommended solution</a> is to:</p>
<ul dir="auto">
<li>create a new service (my strategy)</li>
<li>use a compiler pass to extract the version and version format parameters from the default static strategy my package is compiled with</li>
<li>update the definition of my service with previously extracted parameters</li>
</ul>
<p dir="auto">If I have two packages with the same custom strategy but different versions, I need to duplicate my service declaration and update my compiler. And I cannot create services on-demand during the compiler pass. I could also create my own package configuration for my bundle that would override or extend the default <code class="notranslate">assets.packages</code> service.</p>
<p dir="auto">It's neither convenient nor elegant.</p>
<p dir="auto">I propose to add an optional parameter to set custom strategies:</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="#app/config/config.yml

framework:
    #...
    assets:
        base_urls: //my.cdn.com
        packages:
            pdf:
                version: %version%
                version_format: /name/space/%%2$s/pdf%%1$s
            localized_doc:
                version: %version%
                version_strategy: my.abstract.service.id # default is assets.static_version_strategy falling back on assets.empty_version_strategy if version is null (current behavior)
                version_format: /name/space/%%2$s/doc/%%3$s%/abc%1$s #%3$s would be my locale"><pre class="notranslate"><span class="pl-c"><span class="pl-c">#</span>app/config/config.yml</span>

<span class="pl-ent">framework</span>:
    <span class="pl-c"><span class="pl-c">#</span>...</span>
    <span class="pl-ent">assets</span>:
        <span class="pl-ent">base_urls</span>: <span class="pl-s">//my.cdn.com</span>
        <span class="pl-ent">packages</span>:
            <span class="pl-ent">pdf</span>:
                <span class="pl-ent">version</span>: <span class="pl-s">%version%</span>
                <span class="pl-ent">version_format</span>: <span class="pl-s">/name/space/%%2$s/pdf%%1$s</span>
            <span class="pl-ent">localized_doc</span>:
                <span class="pl-ent">version</span>: <span class="pl-s">%version%</span>
                <span class="pl-ent">version_strategy</span>: <span class="pl-s">my.abstract.service.id </span><span class="pl-c"><span class="pl-c">#</span> default is assets.static_version_strategy falling back on assets.empty_version_strategy if version is null (current behavior)</span>
                <span class="pl-ent">version_format</span>: <span class="pl-s">/name/space/%%2$s/doc/%%3$s%/abc%1$s </span><span class="pl-c"><span class="pl-c">#</span>%3$s would be my locale</span></pre></div>
<p dir="auto">A convenient abstract <code class="notranslate">BaseVersionStrategy</code> class could be provided that would declare <code class="notranslate">setVersion</code> and <code class="notranslate">setVersionFormat</code> to inject said parameters.</p>
<p dir="auto">This solves a particular problem I have where I want to inject known parameters in an asset <code class="notranslate">base_urls</code> or <code class="notranslate">base_path</code>. Please provide your thoughts.</p>