There's no point in really having the visible_id on the A table, other than 
for inheritance.

The point of it being on B (and C, D, E, F, etc.) is that they have unique 
sequences populating those "Visible IDs", so I have can have a B-1 and a 
C-1 and a D-1.

In other words I have my parent table A with 

id, visible_id, type
1, 1, "B"
2, 2, "C"
3, 3, "D"
4, 4, "E"

B
id, visible_id
-----------
1, 1

C
id, visible_id
------------
2, 1

etc.
The alternative (I suppose) would be somehow configuring A.visible_id to 
use a different sequence for every child class table, although a.) i dont 
know if you can do that and b.) it's less desirable to have duplicate 
values in that column.

On Friday, February 14, 2020 at 12:55:47 PM UTC-5, Simon King wrote:
>
> On Fri, Feb 14, 2020 at 5:35 PM Mark Aquino <maqui...@gmail.com 
> <javascript:>> wrote: 
> > 
> > I have a polymorphic class structure like this, with a lot of classes 
> extending the parent class. 
> > In reality I'm using a Mixin that declares the visible_id column and 
> it's defined with @declared_attr.cascading, but for simplicity: 
> > 
> > 
> > 
> > class A(Base): 
> >     __tablename__ = 'a' 
> >     id = Column(Integer, primary_key=True) 
> >    visible_id = Column(Integer) 
> > 
> > class B(A): 
> >     __tablename__ = 'b' 
> >     id = Column(Integer, ForeignKey("A.id"), primary_key=True) 
> >     visible_id = Column(Integer) 
> > 
> > 
> > What I need for my application is to query A.visible_id and return the 
> CHILD values for B.visible_id (and all the others). 
> > 
> > The inheritance works fine, i.e. if i query all As in the database, my 
> response is a list of [B] objects, but unless I directly query B the 
> visible_id from A takes precedence and I cannot query A.visible_id if I 
> remove it from A. 
> > 
> > Can anyone tell me how to configure this? 
> > 
>
> Out of interest, what is the point of having a visible_id column in 
> the B table? I'm having difficulty imagining what it would mean to 
> have an instance of B (which due to inheritance is also an instance of 
> A) which has different values in A.visible_id and B.visible_id. 
>
> Simon 
>

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/546e5a4a-7ab5-4350-888a-6f8d54fb822c%40googlegroups.com.

Reply via email to