On Thu, Apr 26, 2018 at 5:05 AM, Jeremy Flowers
<[email protected]> wrote:
> One of the things I struggle with as a newcomer to Python from Java, is if I
> import a class from a namespace, I expect to find the code in that
> namespace.
> But I find namespace A includes namespace B, so you are forever chasing
> around in IDE's to get your head around the structures..
> Case in point:
> sel = select([Jobmst.jobmst_id, Jobmst.jobmst_name, Jobmst.jobmst_prntid,
> Jobmst.jobmst_type])
> j2 = aliased(sel, name='j2')
> j3 = aliased(Jobmst, name='j3')
> print ('j2 type: ', type(j2))
> print ('j3 type: ', type(j3))
>
> j2 type:  <class 'sqlalchemy.sql.selectable.Alias'>
> j3 type:  <class 'sqlalchemy.orm.util.AliasedClass'>
>
> I had a
> from sqlalchemy.sql import select
>
>
> When I look in that I see Selectable comes from
> .expression.Selectable
>
> I use the docs and find this
> Says. Bases: sqlAlchemy.sqlexpression.ClauseElement
>
>
>
> http://docs.sqlalchemy.org/en/latest/orm/query.html?highlight=aliasedclass#sqlalchemy.orm.util.AliasedClass
>
> Says AliasedClass is ORM equivalent of sqlalchemy.sql.expression.alias()
> ... maintains a reference to 'real' Alias object
> usage via orm.aliased(). orm.with_polymorphic()
>
>
> Alias -> sql.sqlexpression.Alias
> bases sqlalchmy.sql.expression.FromClause
>
> http://docs.sqlalchemy.org/en/latest/core/selectable.html#sqlalchemy.sql.expression.Alias
>
> My this point i'm totally confused. I wanted to ensure j2 or j3 were
> interchangeable.
> But without a big picture diagram I'm totally confused!
>
> Is there such a diagram somewhere with the current 1.2 release please?

"Alias" is a core concept, "AliasedClass" is the ORM concept.   if you
want to work entirely in Core you can make a plain alias() of your
JobMst :  j2 = JobMst.__table__.alias().

Normally if you ask the maintainers of virtually any of the zillion
Python libraries on Pypi, even the really big ones, for a UML diagram,
well, let's just say they wouldn't have that around.   UML is
difficult to apply to highly dynamic languages like Python and you'll
find that people won't be familiar with it (if not hostile to the
whole concept, since they misunderstand its purpose).

However!   As luck would have it, I come from the same Java / UML
world that you do, years ago, so I know where you are, and I do have
some UML at my book chapter here:
http://aosabook.org/en/sqlalchemy.html  and for the layout of the Core
expression elements you will see this in section 20.5.   But these are
not exhaustive UML of every possible class, which would take up
hundreds of pages; there's a general pattern of inheritance throughout
SQLAlchemy and if you know the general idea this should give you an
understanding.

For AliasedClass, this object is a utility object that mediates
between an ORM mapped class and a Core Alias object.   There is a
diagram of how class mappings look in section 20.6 and from there some
not-quite-UML diagrams follow on how some of the ORM mechanisms work.

SQLAlchemy is actually more "java-ish" than most of what you'll find
in Python; because we are a fine-grained library, there is a need for
detailed generated API documentation but all of this is a lot more
ad-hoc than it is in Java, due to the fact that the language is not
statically typed.


>
> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to