This file is indexed.

/usr/share/doc/php-doctrine-orm/html/reference/inheritance-mapping.html is in doctrine-orm-doc 2.4.6-1+deb8u1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>7. Inheritance Mapping &mdash; Doctrine 2 ORM 2 documentation</title>
    <link rel="stylesheet" href="../_static/bootstrap/css/bootstrap.min.css" type="text/css" />
    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <link rel="stylesheet" href="../_static/layout.css" type="text/css" />
    <link rel="stylesheet" href="../_static/configurationblock.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '2',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>

    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/configurationblock.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/configurationblock.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/configurationblock.js"></script>
    <script src="../_static/bootstrap/js/bootstrap.min.js"></script>

    <script type="text/javascript">
    <!--
        $(document).ready(function() {
            $("#versions").change(function() {
                var docsUrl = $(this).val();
                window.location.href = docsUrl;
            });
        });
    -->
    </script>
    <link rel="shortcut icon" href="../_static/doctrine.ico"/>
    <link rel="top" title="Doctrine 2 ORM 2 documentation" href="../index.html" />
    <link rel="next" title="8. Working with Objects" href="working-with-objects.html" />
    <link rel="prev" title="6. Association Mapping" href="association-mapping.html" /> 
  </head>
  <body>
    <div id="wrapper">
      <div id="header">
        <h1 id="h1title"></h1>
        <div id="logo">
          <a href="http://www.doctrine-project.org/">Doctrine - PHP Database Libraries</a>
        </div>
      </div>
      <div id="nav" class="cls">
        <div class="tl cls">
          <ul>
            <li><a target="_top" href="/">home</a></li>
            <li><a class="" target="_top" href="http://www.doctrine-project.org/about">about</a></li>
            <li><a class="" target="_top" href="http://www.doctrine-project.org/projects.html">projects</a></li>
            <li><a class="" target="_top" href="http://www.doctrine-project.org/projects/orm">orm</a></li>
            <li><a class="" target="_top" href="http://www.doctrine-project.org/projects/dbal">dbal</a></li>
            <li><a class="" target="_top" href="http://www.doctrine-project.org/blog">blog</a></li>
            <li><a class="" target="_top" href="http://www.doctrine-project.org/jira">development</a></li>
            <li><a class="" target="_top" href="http://www.doctrine-project.org/contribute">contribute</a></li>
            <li><a class="" target="_top" href="http://www.doctrine-project.org/community">community</a></li>
          </ul>
        </div>
      </div>
      <div id="content" class="cls">
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="working-with-objects.html" title="8. Working with Objects"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="association-mapping.html" title="6. Association Mapping"
             accesskey="P">previous</a> |</li>
        <li><a href="/">Doctrine Homepage</a> &raquo;</li>
        <li><a href="../index.html">Doctrine 2 ORM 2 documentation</a> &raquo;</li> 
      </ul>
    </div>  

        <div class="document">
            <div class="documentwrapper">
                <div class="bodywrapper">

              <div class="body" >
                
  <div class="section" id="inheritance-mapping">
<h1>7. Inheritance Mapping<a class="headerlink" href="#inheritance-mapping" title="Permalink to this headline"></a></h1>
<div class="section" id="mapped-superclasses">
<h2>7.1. Mapped Superclasses<a class="headerlink" href="#mapped-superclasses" title="Permalink to this headline"></a></h2>
<p>A mapped superclass is an abstract or concrete class that provides
persistent entity state and mapping information for its subclasses,
but which is not itself an entity. Typically, the purpose of such a
mapped superclass is to define state and mapping information that
is common to multiple entity classes.</p>
<p>Mapped superclasses, just as regular, non-mapped classes, can
appear in the middle of an otherwise mapped inheritance hierarchy
(through Single Table Inheritance or Class Table Inheritance).</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">A mapped superclass cannot be an entity, it is not query-able and
persistent relationships defined by a mapped superclass must be
unidirectional (with an owning side only). This means that One-To-Many
associations are not possible on a mapped superclass at all.
Furthermore Many-To-Many associations are only possible if the
mapped superclass is only used in exactly one entity at the moment.
For further support of inheritance, the single or
joined table inheritance features have to be used.</p>
</div>
<p>Example:</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>
<span class="sd">/** @MappedSuperclass */</span>
<span class="k">class</span> <span class="nc">MappedSuperclassBase</span>
<span class="p">{</span>
    <span class="sd">/** @Column(type=&quot;integer&quot;) */</span>
    <span class="k">protected</span> <span class="nv">$mapped1</span><span class="p">;</span>
    <span class="sd">/** @Column(type=&quot;string&quot;) */</span>
    <span class="k">protected</span> <span class="nv">$mapped2</span><span class="p">;</span>
    <span class="sd">/**</span>
<span class="sd">     * @OneToOne(targetEntity=&quot;MappedSuperclassRelated1&quot;)</span>
<span class="sd">     * @JoinColumn(name=&quot;related1_id&quot;, referencedColumnName=&quot;id&quot;)</span>
<span class="sd">     */</span>
    <span class="k">protected</span> <span class="nv">$mappedRelated1</span><span class="p">;</span>

    <span class="c1">// ... more fields and methods</span>
<span class="p">}</span>

<span class="sd">/** @Entity */</span>
<span class="k">class</span> <span class="nc">EntitySubClass</span> <span class="k">extends</span> <span class="nx">MappedSuperclassBase</span>
<span class="p">{</span>
    <span class="sd">/** @Id @Column(type=&quot;integer&quot;) */</span>
    <span class="k">private</span> <span class="nv">$id</span><span class="p">;</span>
    <span class="sd">/** @Column(type=&quot;string&quot;) */</span>
    <span class="k">private</span> <span class="nv">$name</span><span class="p">;</span>

    <span class="c1">// ... more fields and methods</span>
<span class="p">}</span>
</pre></div>
</div>
<p>The DDL for the corresponding database schema would look something
like this (this is for SQLite):</p>
<div class="highlight-sql"><div class="highlight"><pre><span class="k">CREATE</span> <span class="k">TABLE</span> <span class="n">EntitySubClass</span> <span class="p">(</span><span class="n">mapped1</span> <span class="nb">INTEGER</span> <span class="k">NOT</span> <span class="k">NULL</span><span class="p">,</span> <span class="n">mapped2</span> <span class="nb">TEXT</span> <span class="k">NOT</span> <span class="k">NULL</span><span class="p">,</span> <span class="n">id</span> <span class="nb">INTEGER</span> <span class="k">NOT</span> <span class="k">NULL</span><span class="p">,</span> <span class="n">name</span> <span class="nb">TEXT</span> <span class="k">NOT</span> <span class="k">NULL</span><span class="p">,</span> <span class="n">related1_id</span> <span class="nb">INTEGER</span> <span class="k">DEFAULT</span> <span class="k">NULL</span><span class="p">,</span> <span class="k">PRIMARY</span> <span class="k">KEY</span><span class="p">(</span><span class="n">id</span><span class="p">))</span>
</pre></div>
</div>
<p>As you can see from this DDL snippet, there is only a single table
for the entity subclass. All the mappings from the mapped
superclass were inherited to the subclass as if they had been
defined on that class directly.</p>
</div>
<div class="section" id="single-table-inheritance">
<h2>7.2. Single Table Inheritance<a class="headerlink" href="#single-table-inheritance" title="Permalink to this headline"></a></h2>
<p><a class="reference external" href="http://martinfowler.com/eaaCatalog/singleTableInheritance.html">Single Table Inheritance</a>
is an inheritance mapping strategy where all classes of a hierarchy
are mapped to a single database table. In order to distinguish
which row represents which type in the hierarchy a so-called
discriminator column is used.</p>
<p>Example:</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>
<span class="k">namespace</span> <span class="nx">MyProject\Model</span><span class="p">;</span>

<span class="sd">/**</span>
<span class="sd"> * @Entity</span>
<span class="sd"> * @InheritanceType(&quot;SINGLE_TABLE&quot;)</span>
<span class="sd"> * @DiscriminatorColumn(name=&quot;discr&quot;, type=&quot;string&quot;)</span>
<span class="sd"> * @DiscriminatorMap({&quot;person&quot; = &quot;Person&quot;, &quot;employee&quot; = &quot;Employee&quot;})</span>
<span class="sd"> */</span>
<span class="k">class</span> <span class="nc">Person</span>
<span class="p">{</span>
    <span class="c1">// ...</span>
<span class="p">}</span>

<span class="sd">/**</span>
<span class="sd"> * @Entity</span>
<span class="sd"> */</span>
<span class="k">class</span> <span class="nc">Employee</span> <span class="k">extends</span> <span class="nx">Person</span>
<span class="p">{</span>
    <span class="c1">// ...</span>
<span class="p">}</span>
</pre></div>
</div>
<p>Things to note:</p>
<ul class="simple">
<li>The &#64;InheritanceType, &#64;DiscriminatorColumn and &#64;DiscriminatorMap
must be specified on the topmost class that is part of the mapped
entity hierarchy.</li>
<li>The &#64;DiscriminatorMap specifies which values of the
discriminator column identify a row as being of a certain type. In
the case above a value of &#8220;person&#8221; identifies a row as being of
type <tt class="docutils literal"><span class="pre">Person</span></tt> and &#8220;employee&#8221; identifies a row as being of type
<tt class="docutils literal"><span class="pre">Employee</span></tt>.</li>
<li>The names of the classes in the discriminator map do not need to
be fully qualified if the classes are contained in the same
namespace as the entity class on which the discriminator map is
applied.</li>
</ul>
<div class="section" id="design-time-considerations">
<h3>7.2.1. Design-time considerations<a class="headerlink" href="#design-time-considerations" title="Permalink to this headline"></a></h3>
<p>This mapping approach works well when the type hierarchy is fairly
simple and stable. Adding a new type to the hierarchy and adding
fields to existing supertypes simply involves adding new columns to
the table, though in large deployments this may have an adverse
impact on the index and column layout inside the database.</p>
</div>
<div class="section" id="performance-impact">
<h3>7.2.2. Performance impact<a class="headerlink" href="#performance-impact" title="Permalink to this headline"></a></h3>
<p>This strategy is very efficient for querying across all types in
the hierarchy or for specific types. No table joins are required,
only a WHERE clause listing the type identifiers. In particular,
relationships involving types that employ this mapping strategy are
very performant.</p>
<p>There is a general performance consideration with Single Table
Inheritance: If the target-entity of a many-to-one or one-to-one
association is an STI entity, it is preferable for performance reasons that it
be a leaf entity in the inheritance hierarchy, (ie. have no subclasses).
Otherwise Doctrine <em>CANNOT</em> create proxy instances
of this entity and will <em>ALWAYS</em> load the entity eagerly.</p>
</div>
<div class="section" id="sql-schema-considerations">
<h3>7.2.3. SQL Schema considerations<a class="headerlink" href="#sql-schema-considerations" title="Permalink to this headline"></a></h3>
<p>For Single-Table-Inheritance to work in scenarios where you are
using either a legacy database schema or a self-written database
schema you have to make sure that all columns that are not in the
root entity but in any of the different sub-entities has to allows
null values. Columns that have NOT NULL constraints have to be on
the root entity of the single-table inheritance hierarchy.</p>
</div>
</div>
<div class="section" id="class-table-inheritance">
<h2>7.3. Class Table Inheritance<a class="headerlink" href="#class-table-inheritance" title="Permalink to this headline"></a></h2>
<p><a class="reference external" href="http://martinfowler.com/eaaCatalog/classTableInheritance.html">Class Table Inheritance</a>
is an inheritance mapping strategy where each class in a hierarchy
is mapped to several tables: its own table and the tables of all
parent classes. The table of a child class is linked to the table
of a parent class through a foreign key constraint. Doctrine 2
implements this strategy through the use of a discriminator column
in the topmost table of the hierarchy because this is the easiest
way to achieve polymorphic queries with Class Table Inheritance.</p>
<p>Example:</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>
<span class="k">namespace</span> <span class="nx">MyProject\Model</span><span class="p">;</span>

<span class="sd">/**</span>
<span class="sd"> * @Entity</span>
<span class="sd"> * @InheritanceType(&quot;JOINED&quot;)</span>
<span class="sd"> * @DiscriminatorColumn(name=&quot;discr&quot;, type=&quot;string&quot;)</span>
<span class="sd"> * @DiscriminatorMap({&quot;person&quot; = &quot;Person&quot;, &quot;employee&quot; = &quot;Employee&quot;})</span>
<span class="sd"> */</span>
<span class="k">class</span> <span class="nc">Person</span>
<span class="p">{</span>
    <span class="c1">// ...</span>
<span class="p">}</span>

<span class="sd">/** @Entity */</span>
<span class="k">class</span> <span class="nc">Employee</span> <span class="k">extends</span> <span class="nx">Person</span>
<span class="p">{</span>
    <span class="c1">// ...</span>
<span class="p">}</span>
</pre></div>
</div>
<p>Things to note:</p>
<ul class="simple">
<li>The &#64;InheritanceType, &#64;DiscriminatorColumn and &#64;DiscriminatorMap
must be specified on the topmost class that is part of the mapped
entity hierarchy.</li>
<li>The &#64;DiscriminatorMap specifies which values of the
discriminator column identify a row as being of which type. In the
case above a value of &#8220;person&#8221; identifies a row as being of type
<tt class="docutils literal"><span class="pre">Person</span></tt> and &#8220;employee&#8221; identifies a row as being of type
<tt class="docutils literal"><span class="pre">Employee</span></tt>.</li>
<li>The names of the classes in the discriminator map do not need to
be fully qualified if the classes are contained in the same
namespace as the entity class on which the discriminator map is
applied.</li>
</ul>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">When you do not use the SchemaTool to generate the
required SQL you should know that deleting a class table
inheritance makes use of the foreign key property
<tt class="docutils literal"><span class="pre">ON</span> <span class="pre">DELETE</span> <span class="pre">CASCADE</span></tt> in all database implementations. A failure to
implement this yourself will lead to dead rows in the database.</p>
</div>
<div class="section" id="id3">
<h3>7.3.1. Design-time considerations<a class="headerlink" href="#id3" title="Permalink to this headline"></a></h3>
<p>Introducing a new type to the hierarchy, at any level, simply
involves interjecting a new table into the schema. Subtypes of that
type will automatically join with that new type at runtime.
Similarly, modifying any entity type in the hierarchy by adding,
modifying or removing fields affects only the immediate table
mapped to that type. This mapping strategy provides the greatest
flexibility at design time, since changes to any type are always
limited to that type&#8217;s dedicated table.</p>
</div>
<div class="section" id="id4">
<h3>7.3.2. Performance impact<a class="headerlink" href="#id4" title="Permalink to this headline"></a></h3>
<p>This strategy inherently requires multiple JOIN operations to
perform just about any query which can have a negative impact on
performance, especially with large tables and/or large hierarchies.
When partial objects are allowed, either globally or on the
specific query, then querying for any type will not cause the
tables of subtypes to be OUTER JOINed which can increase
performance but the resulting partial objects will not fully load
themselves on access of any subtype fields, so accessing fields of
subtypes after such a query is not safe.</p>
<p>There is a general performance consideration with Class Table
Inheritance: If the target-entity of a many-to-one or one-to-one
association is a CTI entity, it is preferable for performance reasons that it
be a leaf entity in the inheritance hierarchy, (ie. have no subclasses).
Otherwise Doctrine <em>CANNOT</em> create proxy instances
of this entity and will <em>ALWAYS</em> load the entity eagerly.</p>
</div>
<div class="section" id="id5">
<h3>7.3.3. SQL Schema considerations<a class="headerlink" href="#id5" title="Permalink to this headline"></a></h3>
<p>For each entity in the Class-Table Inheritance hierarchy all the
mapped fields have to be columns on the table of this entity.
Additionally each child table has to have an id column that matches
the id column definition on the root table (except for any sequence
or auto-increment details). Furthermore each child table has to
have a foreign key pointing from the id column to the root table id
column and cascading on delete.</p>
</div>
</div>
<div class="section" id="overrides">
<h2>7.4. Overrides<a class="headerlink" href="#overrides" title="Permalink to this headline"></a></h2>
<p>Used to override a mapping for an entity field or relationship.
May be applied to an entity that extends a mapped superclass
to override a relationship or field mapping defined by the mapped superclass.</p>
<div class="section" id="association-override">
<h3>7.4.1. Association Override<a class="headerlink" href="#association-override" title="Permalink to this headline"></a></h3>
<p>Override a mapping for an entity relationship.</p>
<p>Could be used by an entity that extends a mapped superclass
to override a relationship mapping defined by the mapped superclass.</p>
<p>Example:</p>
<div class="configuration-block">
<ul class="simple">
<li><em>PHP</em><div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>
<span class="c1">// user mapping</span>
<span class="k">namespace</span> <span class="nx">MyProject\Model</span><span class="p">;</span>
<span class="sd">/**</span>
<span class="sd"> * @MappedSuperclass</span>
<span class="sd"> */</span>
<span class="k">class</span> <span class="nc">User</span>
<span class="p">{</span>
    <span class="c1">//other fields mapping</span>

    <span class="sd">/**</span>
<span class="sd">     * @ManyToMany(targetEntity=&quot;Group&quot;, inversedBy=&quot;users&quot;)</span>
<span class="sd">     * @JoinTable(name=&quot;users_groups&quot;,</span>
<span class="sd">     *  joinColumns={@JoinColumn(name=&quot;user_id&quot;, referencedColumnName=&quot;id&quot;)},</span>
<span class="sd">     *  inverseJoinColumns={@JoinColumn(name=&quot;group_id&quot;, referencedColumnName=&quot;id&quot;)}</span>
<span class="sd">     * )</span>
<span class="sd">     */</span>
    <span class="k">protected</span> <span class="nv">$groups</span><span class="p">;</span>

    <span class="sd">/**</span>
<span class="sd">     * @ManyToOne(targetEntity=&quot;Address&quot;)</span>
<span class="sd">     * @JoinColumn(name=&quot;address_id&quot;, referencedColumnName=&quot;id&quot;)</span>
<span class="sd">     */</span>
    <span class="k">protected</span> <span class="nv">$address</span><span class="p">;</span>
<span class="p">}</span>

<span class="c1">// admin mapping</span>
<span class="k">namespace</span> <span class="nx">MyProject\Model</span><span class="p">;</span>
<span class="sd">/**</span>
<span class="sd"> * @Entity</span>
<span class="sd"> * @AssociationOverrides({</span>
<span class="sd"> *      @AssociationOverride(name=&quot;groups&quot;,</span>
<span class="sd"> *          joinTable=@JoinTable(</span>
<span class="sd"> *              name=&quot;users_admingroups&quot;,</span>
<span class="sd"> *              joinColumns=@JoinColumn(name=&quot;adminuser_id&quot;),</span>
<span class="sd"> *              inverseJoinColumns=@JoinColumn(name=&quot;admingroup_id&quot;)</span>
<span class="sd"> *          )</span>
<span class="sd"> *      ),</span>
<span class="sd"> *      @AssociationOverride(name=&quot;address&quot;,</span>
<span class="sd"> *          joinColumns=@JoinColumn(</span>
<span class="sd"> *              name=&quot;adminaddress_id&quot;, referencedColumnName=&quot;id&quot;</span>
<span class="sd"> *          )</span>
<span class="sd"> *      )</span>
<span class="sd"> * })</span>
<span class="sd"> */</span>
<span class="k">class</span> <span class="nc">Admin</span> <span class="k">extends</span> <span class="nx">User</span>
<span class="p">{</span>
<span class="p">}</span>
</pre></div>
</div>
</li>
<li><em>XML</em><div class="highlight-xml"><div class="highlight"><pre><span class="c">&lt;!-- user mapping --&gt;</span>
<span class="nt">&lt;doctrine-mapping&gt;</span>
  <span class="nt">&lt;mapped-superclass</span> <span class="na">name=</span><span class="s">&quot;MyProject\Model\User&quot;</span><span class="nt">&gt;</span>
        <span class="c">&lt;!-- other fields mapping --&gt;</span>
        <span class="nt">&lt;many-to-many</span> <span class="na">field=</span><span class="s">&quot;groups&quot;</span> <span class="na">target-entity=</span><span class="s">&quot;Group&quot;</span> <span class="na">inversed-by=</span><span class="s">&quot;users&quot;</span><span class="nt">&gt;</span>
            <span class="nt">&lt;cascade&gt;</span>
                <span class="nt">&lt;cascade-persist/&gt;</span>
                <span class="nt">&lt;cascade-merge/&gt;</span>
                <span class="nt">&lt;cascade-detach/&gt;</span>
            <span class="nt">&lt;/cascade&gt;</span>
            <span class="nt">&lt;join-table</span> <span class="na">name=</span><span class="s">&quot;users_groups&quot;</span><span class="nt">&gt;</span>
                <span class="nt">&lt;join-columns&gt;</span>
                    <span class="nt">&lt;join-column</span> <span class="na">name=</span><span class="s">&quot;user_id&quot;</span> <span class="na">referenced-column-name=</span><span class="s">&quot;id&quot;</span> <span class="nt">/&gt;</span>
                <span class="nt">&lt;/join-columns&gt;</span>
                <span class="nt">&lt;inverse-join-columns&gt;</span>
                    <span class="nt">&lt;join-column</span> <span class="na">name=</span><span class="s">&quot;group_id&quot;</span> <span class="na">referenced-column-name=</span><span class="s">&quot;id&quot;</span> <span class="nt">/&gt;</span>
                <span class="nt">&lt;/inverse-join-columns&gt;</span>
            <span class="nt">&lt;/join-table&gt;</span>
        <span class="nt">&lt;/many-to-many&gt;</span>
    <span class="nt">&lt;/mapped-superclass&gt;</span>
<span class="nt">&lt;/doctrine-mapping&gt;</span>

<span class="c">&lt;!-- admin mapping --&gt;</span>
<span class="nt">&lt;doctrine-mapping&gt;</span>
    <span class="nt">&lt;entity</span> <span class="na">name=</span><span class="s">&quot;MyProject\Model\Admin&quot;</span><span class="nt">&gt;</span>
        <span class="nt">&lt;association-overrides&gt;</span>
            <span class="nt">&lt;association-override</span> <span class="na">name=</span><span class="s">&quot;groups&quot;</span><span class="nt">&gt;</span>
                <span class="nt">&lt;join-table</span> <span class="na">name=</span><span class="s">&quot;users_admingroups&quot;</span><span class="nt">&gt;</span>
                    <span class="nt">&lt;join-columns&gt;</span>
                        <span class="nt">&lt;join-column</span> <span class="na">name=</span><span class="s">&quot;adminuser_id&quot;</span><span class="nt">/&gt;</span>
                    <span class="nt">&lt;/join-columns&gt;</span>
                    <span class="nt">&lt;inverse-join-columns&gt;</span>
                        <span class="nt">&lt;join-column</span> <span class="na">name=</span><span class="s">&quot;admingroup_id&quot;</span><span class="nt">/&gt;</span>
                    <span class="nt">&lt;/inverse-join-columns&gt;</span>
                <span class="nt">&lt;/join-table&gt;</span>
            <span class="nt">&lt;/association-override&gt;</span>
            <span class="nt">&lt;association-override</span> <span class="na">name=</span><span class="s">&quot;address&quot;</span><span class="nt">&gt;</span>
                <span class="nt">&lt;join-columns&gt;</span>
                    <span class="nt">&lt;join-column</span> <span class="na">name=</span><span class="s">&quot;adminaddress_id&quot;</span> <span class="na">referenced-column-name=</span><span class="s">&quot;id&quot;</span><span class="nt">/&gt;</span>
                <span class="nt">&lt;/join-columns&gt;</span>
            <span class="nt">&lt;/association-override&gt;</span>
        <span class="nt">&lt;/association-overrides&gt;</span>
    <span class="nt">&lt;/entity&gt;</span>
<span class="nt">&lt;/doctrine-mapping&gt;</span>
</pre></div>
</div>
</li>
<li><em>YAML</em><div class="highlight-yaml"><div class="highlight"><pre><span class="c1"># user mapping</span>
<span class="l-Scalar-Plain">MyProject\Model\User</span><span class="p-Indicator">:</span>
  <span class="l-Scalar-Plain">type</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">mappedSuperclass</span>
  <span class="c1"># other fields mapping</span>
  <span class="l-Scalar-Plain">manyToOne</span><span class="p-Indicator">:</span>
    <span class="l-Scalar-Plain">address</span><span class="p-Indicator">:</span>
      <span class="l-Scalar-Plain">targetEntity</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">Address</span>
      <span class="l-Scalar-Plain">joinColumn</span><span class="p-Indicator">:</span>
        <span class="l-Scalar-Plain">name</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">address_id</span>
        <span class="l-Scalar-Plain">referencedColumnName</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">id</span>
      <span class="l-Scalar-Plain">cascade</span><span class="p-Indicator">:</span> <span class="p-Indicator">[</span> <span class="nv">persist</span><span class="p-Indicator">,</span> <span class="nv">merge</span> <span class="p-Indicator">]</span>
  <span class="l-Scalar-Plain">manyToMany</span><span class="p-Indicator">:</span>
    <span class="l-Scalar-Plain">groups</span><span class="p-Indicator">:</span>
      <span class="l-Scalar-Plain">targetEntity</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">Group</span>
      <span class="l-Scalar-Plain">joinTable</span><span class="p-Indicator">:</span>
        <span class="l-Scalar-Plain">name</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">users_groups</span>
        <span class="l-Scalar-Plain">joinColumns</span><span class="p-Indicator">:</span>
          <span class="l-Scalar-Plain">user_id</span><span class="p-Indicator">:</span>
            <span class="l-Scalar-Plain">referencedColumnName</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">id</span>
        <span class="l-Scalar-Plain">inverseJoinColumns</span><span class="p-Indicator">:</span>
          <span class="l-Scalar-Plain">group_id</span><span class="p-Indicator">:</span>
            <span class="l-Scalar-Plain">referencedColumnName</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">id</span>
      <span class="l-Scalar-Plain">cascade</span><span class="p-Indicator">:</span> <span class="p-Indicator">[</span> <span class="nv">persist</span><span class="p-Indicator">,</span> <span class="nv">merge</span><span class="p-Indicator">,</span> <span class="nv">detach</span> <span class="p-Indicator">]</span>

<span class="c1"># admin mapping</span>
<span class="l-Scalar-Plain">MyProject\Model\Admin</span><span class="p-Indicator">:</span>
  <span class="l-Scalar-Plain">type</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">entity</span>
  <span class="l-Scalar-Plain">associationOverride</span><span class="p-Indicator">:</span>
    <span class="l-Scalar-Plain">address</span><span class="p-Indicator">:</span>
      <span class="l-Scalar-Plain">joinColumn</span><span class="p-Indicator">:</span>
        <span class="l-Scalar-Plain">adminaddress_id</span><span class="p-Indicator">:</span>
          <span class="l-Scalar-Plain">name</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">adminaddress_id</span>
          <span class="l-Scalar-Plain">referencedColumnName</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">id</span>
    <span class="l-Scalar-Plain">groups</span><span class="p-Indicator">:</span>
      <span class="l-Scalar-Plain">joinTable</span><span class="p-Indicator">:</span>
        <span class="l-Scalar-Plain">name</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">users_admingroups</span>
        <span class="l-Scalar-Plain">joinColumns</span><span class="p-Indicator">:</span>
          <span class="l-Scalar-Plain">adminuser_id</span><span class="p-Indicator">:</span>
            <span class="l-Scalar-Plain">referencedColumnName</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">id</span>
        <span class="l-Scalar-Plain">inverseJoinColumns</span><span class="p-Indicator">:</span>
          <span class="l-Scalar-Plain">admingroup_id</span><span class="p-Indicator">:</span>
            <span class="l-Scalar-Plain">referencedColumnName</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">id</span>
</pre></div>
</div>
</li>
</ul>
</div>
<p>Things to note:</p>
<ul class="simple">
<li>The &#8220;association override&#8221; specifies the overrides base on the property name.</li>
<li>This feature is available for all kind of associations. (OneToOne, OneToMany, ManyToOne, ManyToMany)</li>
<li>The association type <em>CANNOT</em> be changed.</li>
<li>The override could redefine the joinTables or joinColumns depending on the association type.</li>
</ul>
</div>
<div class="section" id="attribute-override">
<h3>7.4.2. Attribute Override<a class="headerlink" href="#attribute-override" title="Permalink to this headline"></a></h3>
<p>Override the mapping of a field.</p>
<p>Could be used by an entity that extends a mapped superclass to override a field mapping defined by the mapped superclass.</p>
<div class="configuration-block">
<ul class="simple">
<li><em>PHP</em><div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>
<span class="c1">// user mapping</span>
<span class="k">namespace</span> <span class="nx">MyProject\Model</span><span class="p">;</span>
<span class="sd">/**</span>
<span class="sd"> * @MappedSuperclass</span>
<span class="sd"> */</span>
<span class="k">class</span> <span class="nc">User</span>
<span class="p">{</span>
    <span class="sd">/** @Id @GeneratedValue @Column(type=&quot;integer&quot;, name=&quot;user_id&quot;, length=150) */</span>
    <span class="k">protected</span> <span class="nv">$id</span><span class="p">;</span>

    <span class="sd">/** @Column(name=&quot;user_name&quot;, nullable=true, unique=false, length=250) */</span>
    <span class="k">protected</span> <span class="nv">$name</span><span class="p">;</span>

    <span class="c1">// other fields mapping</span>
<span class="p">}</span>

<span class="c1">// guest mapping</span>
<span class="k">namespace</span> <span class="nx">MyProject\Model</span><span class="p">;</span>
<span class="sd">/**</span>
<span class="sd"> * @Entity</span>
<span class="sd"> * @AttributeOverrides({</span>
<span class="sd"> *      @AttributeOverride(name=&quot;id&quot;,</span>
<span class="sd"> *          column=@Column(</span>
<span class="sd"> *              name     = &quot;guest_id&quot;,</span>
<span class="sd"> *              type     = &quot;integer&quot;,</span>
<span class="sd">                length   = 140</span>
<span class="sd"> *          )</span>
<span class="sd"> *      ),</span>
<span class="sd"> *      @AttributeOverride(name=&quot;name&quot;,</span>
<span class="sd"> *          column=@Column(</span>
<span class="sd"> *              name     = &quot;guest_name&quot;,</span>
<span class="sd"> *              nullable = false,</span>
<span class="sd"> *              unique   = true,</span>
<span class="sd">                length   = 240</span>
<span class="sd"> *          )</span>
<span class="sd"> *      )</span>
<span class="sd"> * })</span>
<span class="sd"> */</span>
<span class="k">class</span> <span class="nc">Guest</span> <span class="k">extends</span> <span class="nx">User</span>
<span class="p">{</span>
<span class="p">}</span>
</pre></div>
</div>
</li>
<li><em>XML</em><div class="highlight-xml"><div class="highlight"><pre><span class="c">&lt;!-- user mapping --&gt;</span>
<span class="nt">&lt;doctrine-mapping&gt;</span>
  <span class="nt">&lt;mapped-superclass</span> <span class="na">name=</span><span class="s">&quot;MyProject\Model\User&quot;</span><span class="nt">&gt;</span>
        <span class="nt">&lt;id</span> <span class="na">name=</span><span class="s">&quot;id&quot;</span> <span class="na">type=</span><span class="s">&quot;integer&quot;</span> <span class="na">column=</span><span class="s">&quot;user_id&quot;</span> <span class="na">length=</span><span class="s">&quot;150&quot;</span><span class="nt">&gt;</span>
            <span class="nt">&lt;generator</span> <span class="na">strategy=</span><span class="s">&quot;AUTO&quot;</span><span class="nt">/&gt;</span>
        <span class="nt">&lt;/id&gt;</span>
        <span class="nt">&lt;field</span> <span class="na">name=</span><span class="s">&quot;name&quot;</span> <span class="na">column=</span><span class="s">&quot;user_name&quot;</span> <span class="na">type=</span><span class="s">&quot;string&quot;</span> <span class="na">length=</span><span class="s">&quot;250&quot;</span> <span class="na">nullable=</span><span class="s">&quot;true&quot;</span> <span class="na">unique=</span><span class="s">&quot;false&quot;</span> <span class="nt">/&gt;</span>
        <span class="nt">&lt;many-to-one</span> <span class="na">field=</span><span class="s">&quot;address&quot;</span> <span class="na">target-entity=</span><span class="s">&quot;Address&quot;</span><span class="nt">&gt;</span>
            <span class="nt">&lt;cascade&gt;</span>
                <span class="nt">&lt;cascade-persist/&gt;</span>
                <span class="nt">&lt;cascade-merge/&gt;</span>
            <span class="nt">&lt;/cascade&gt;</span>
            <span class="nt">&lt;join-column</span> <span class="na">name=</span><span class="s">&quot;address_id&quot;</span> <span class="na">referenced-column-name=</span><span class="s">&quot;id&quot;</span><span class="nt">/&gt;</span>
        <span class="nt">&lt;/many-to-one&gt;</span>
        <span class="c">&lt;!-- other fields mapping --&gt;</span>
    <span class="nt">&lt;/mapped-superclass&gt;</span>
<span class="nt">&lt;/doctrine-mapping&gt;</span>

<span class="c">&lt;!-- admin mapping --&gt;</span>
<span class="nt">&lt;doctrine-mapping&gt;</span>
    <span class="nt">&lt;entity</span> <span class="na">name=</span><span class="s">&quot;MyProject\Model\Guest&quot;</span><span class="nt">&gt;</span>
        <span class="nt">&lt;attribute-overrides&gt;</span>
            <span class="nt">&lt;attribute-override</span> <span class="na">name=</span><span class="s">&quot;id&quot;</span><span class="nt">&gt;</span>
                <span class="nt">&lt;field</span> <span class="na">column=</span><span class="s">&quot;guest_id&quot;</span> <span class="na">length=</span><span class="s">&quot;140&quot;</span><span class="nt">/&gt;</span>
            <span class="nt">&lt;/attribute-override&gt;</span>
            <span class="nt">&lt;attribute-override</span> <span class="na">name=</span><span class="s">&quot;name&quot;</span><span class="nt">&gt;</span>
                <span class="nt">&lt;field</span> <span class="na">column=</span><span class="s">&quot;guest_name&quot;</span> <span class="na">type=</span><span class="s">&quot;string&quot;</span> <span class="na">length=</span><span class="s">&quot;240&quot;</span> <span class="na">nullable=</span><span class="s">&quot;false&quot;</span> <span class="na">unique=</span><span class="s">&quot;true&quot;</span> <span class="nt">/&gt;</span>
            <span class="nt">&lt;/attribute-override&gt;</span>
        <span class="nt">&lt;/attribute-overrides&gt;</span>
    <span class="nt">&lt;/entity&gt;</span>
<span class="nt">&lt;/doctrine-mapping&gt;</span>
</pre></div>
</div>
</li>
<li><em>YAML</em><div class="highlight-yaml"><div class="highlight"><pre><span class="c1"># user mapping</span>
<span class="l-Scalar-Plain">MyProject\Model\User</span><span class="p-Indicator">:</span>
  <span class="l-Scalar-Plain">type</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">mappedSuperclass</span>
  <span class="l-Scalar-Plain">id</span><span class="p-Indicator">:</span>
    <span class="l-Scalar-Plain">id</span><span class="p-Indicator">:</span>
      <span class="l-Scalar-Plain">type</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">integer</span>
      <span class="l-Scalar-Plain">column</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">user_id</span>
      <span class="l-Scalar-Plain">length</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">150</span>
      <span class="l-Scalar-Plain">generator</span><span class="p-Indicator">:</span>
        <span class="l-Scalar-Plain">strategy</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">AUTO</span>
  <span class="l-Scalar-Plain">fields</span><span class="p-Indicator">:</span>
    <span class="l-Scalar-Plain">name</span><span class="p-Indicator">:</span>
      <span class="l-Scalar-Plain">type</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">string</span>
      <span class="l-Scalar-Plain">column</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">user_name</span>
      <span class="l-Scalar-Plain">length</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">250</span>
      <span class="l-Scalar-Plain">nullable</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span>
      <span class="l-Scalar-Plain">unique</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">false</span>
  <span class="c1">#other fields mapping</span>


<span class="c1"># guest mapping</span>
<span class="l-Scalar-Plain">MyProject\Model\Guest</span><span class="p-Indicator">:</span>
  <span class="l-Scalar-Plain">type</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">entity</span>
  <span class="l-Scalar-Plain">attributeOverride</span><span class="p-Indicator">:</span>
    <span class="l-Scalar-Plain">id</span><span class="p-Indicator">:</span>
      <span class="l-Scalar-Plain">column</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">guest_id</span>
      <span class="l-Scalar-Plain">type</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">integer</span>
      <span class="l-Scalar-Plain">length</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">140</span>
    <span class="l-Scalar-Plain">name</span><span class="p-Indicator">:</span>
      <span class="l-Scalar-Plain">column</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">guest_name</span>
      <span class="l-Scalar-Plain">type</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">string</span>
      <span class="l-Scalar-Plain">length</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">240</span>
      <span class="l-Scalar-Plain">nullable</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">false</span>
      <span class="l-Scalar-Plain">unique</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span>
</pre></div>
</div>
</li>
</ul>
</div>
<p>Things to note:</p>
<ul class="simple">
<li>The &#8220;attribute override&#8221; specifies the overrides base on the property name.</li>
<li>The column type <em>CANNOT</em> be changed. if the column type is not equals you got a <tt class="docutils literal"><span class="pre">MappingException</span></tt></li>
<li>The override can redefine all the column except the type.</li>
</ul>
</div>
</div>
</div>


              </div>
                </div>

            </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
             
            <div id="searchbox" style="">
              <h3>Search</h3>
                <form class="search" action="http://readthedocs.org/search/project/" method="get">
                  <input type="text" name="q" size="18">
                  <input type="submit" value="Go">
                  <input type="hidden" name="selected_facets" value="project:">
                </form>
            </div>
            <h3><a href="../index.html">Table Of Contents</a></h3>
            <ul>
<li><a class="reference internal" href="#">7. Inheritance Mapping</a><ul>
<li><a class="reference internal" href="#mapped-superclasses">7.1. Mapped Superclasses</a></li>
<li><a class="reference internal" href="#single-table-inheritance">7.2. Single Table Inheritance</a><ul>
<li><a class="reference internal" href="#design-time-considerations">7.2.1. Design-time considerations</a></li>
<li><a class="reference internal" href="#performance-impact">7.2.2. Performance impact</a></li>
<li><a class="reference internal" href="#sql-schema-considerations">7.2.3. SQL Schema considerations</a></li>
</ul>
</li>
<li><a class="reference internal" href="#class-table-inheritance">7.3. Class Table Inheritance</a><ul>
<li><a class="reference internal" href="#id3">7.3.1. Design-time considerations</a></li>
<li><a class="reference internal" href="#id4">7.3.2. Performance impact</a></li>
<li><a class="reference internal" href="#id5">7.3.3. SQL Schema considerations</a></li>
</ul>
</li>
<li><a class="reference internal" href="#overrides">7.4. Overrides</a><ul>
<li><a class="reference internal" href="#association-override">7.4.1. Association Override</a></li>
<li><a class="reference internal" href="#attribute-override">7.4.2. Attribute Override</a></li>
</ul>
</li>
</ul>
</li>
</ul>

            <h4>Previous topic</h4>
            <p class="topless"><a href="association-mapping.html"
                                  title="previous chapter">6. Association Mapping</a></p>
            <h4>Next topic</h4>
            <p class="topless"><a href="working-with-objects.html"
                                  title="next chapter">8. Working with Objects</a></p>
            <h3>This Page</h3>
            <ul class="this-page-menu">
              <li><a href="../_sources/reference/inheritance-mapping.txt"
                     rel="nofollow">Show Source</a></li>
            </ul>
        </div>
      </div>
          <div class="clearer"></div>
        </div>
          <div class="footer">
              &copy; Copyright 2010-12, Doctrine Project Team.
              Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.2.3.
            <br/>
            <a target="_BLANK" href="http://www.servergrove.com"><img src="../_static/servergrove.jpg" /></a>      <br/><br/>
            <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
              <input type="hidden" name="cmd" value="_s-xclick" />
              <input type="hidden" name="hosted_button_id" value="BAE2E3XANQ77Y" />
              <input type="Submit" value="Donate via PayPal" />
            </form>
          </div>
      </div>

      <div id="bot-rcnr">
        <div class="tl"><!-- corner --></div>
      </div>
    </div>

  <a class="githublink" href="http://github.com/doctrine">Fork me on GitHub</a>
  </body>
</html>