<p dir="auto"><strong>Migrated issue, originally created by Anonymous</strong></p>
<p dir="auto">in the following schema:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="+-------------------------------------------*
|   people (abstract) --- has a --- car     |
|         ^    ^                     ^      |
|         |    |                     |      |
| engineers    managers            offroad  |
|                                           |
+-------------------------------------------+"><pre class="notranslate"><code class="notranslate">+-------------------------------------------*
|   people (abstract) --- has a --- car     |
|         ^    ^                     ^      |
|         |    |                     |      |
| engineers    managers            offroad  |
|                                           |
+-------------------------------------------+
</code></pre></div>
<p dir="auto">you define a ploymorphic car_mapper for car and offroad<br>
you define a polymorphic people_mapper for engineers and managers with a property 'car' relation(car_mapper)</p>
<p dir="auto">after clearing the session, if you query a Person and you retrieve his car property (person.car), the object returned is wrong but the reference to the car (person.car_id) is right.<br>
see attached test case</p>
<hr>
<p dir="auto">Attachments: <a href="../wiki/imported_issue_attachments/493/493.py">493.py</a></p>
<p dir="auto"><strong>Migrated issue, originally created by Anonymous</strong></p>
<p dir="auto">I could not find a way to do that and I think it's an enhancement request.</p>
<p dir="auto">Would be really nice to have a way to cast between classes. I mean, when you have Person and Employee classes, for example (where Employee is a subclasse of Person), would be great to create an Employee based on a previous saved Person.</p>
<p dir="auto">Today, if you try to do:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; # myPerson = a Person object from database
&gt;&gt;&gt; myPerson.__class__ = Employee
&gt;&gt;&gt; myPerson.working = True
&gt;&gt;&gt; session.save(myPerson)
&gt;&gt;&gt; session.flush()"><pre class="notranslate"><code class="notranslate">&gt;&gt;&gt; # myPerson = a Person object from database
&gt;&gt;&gt; myPerson.__class__ = Employee
&gt;&gt;&gt; myPerson.working = True
&gt;&gt;&gt; session.save(myPerson)
&gt;&gt;&gt; session.flush()
</code></pre></div>
<p dir="auto">you would get an identity change Exception:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Can't change the identity of instance Employee@-0x4873a7d4 in session (existing identity: (&lt;class '__main__.Person'&gt;, (1,), None); new identity: (&lt;class '__main__.Employee'&gt;, (1,), None))"><pre class="notranslate"><code class="notranslate">Can't change the identity of instance Employee@-0x4873a7d4 in session (existing identity: (&lt;class '__main__.Person'&gt;, (1,), None); new identity: (&lt;class '__main__.Employee'&gt;, (1,), None))
</code></pre></div>
<p dir="auto">(see attached script for details)</p>
<p dir="auto">Would be possible to do something like this?</p>
<hr>
<p dir="auto">Attachments: <a href="../wiki/imported_issue_attachments/648/modified_teste.py">modified_teste.py</a> | <a href="../wiki/imported_issue_attachments/648/sqlalchemy_cast.2.patch">sqlalchemy_cast.2.patch</a> | <a href="../wiki/imported_issue_attachments/648/sqlalchemy_cast.patch">sqlalchemy_cast.patch</a> | <a href="../wiki/imported_issue_attachments/648/teste.py">teste.py</a></p>