Hi,

I would like to find an automated way to collect all columns of any mapped
class which type is declared as

  ColType.as_mutable(ConcreteType)
  
In an application I'm developing I use sqlalchemy-media to handle multi-media
"attachments" to avoid storing the actual media within the database. 

As an example, consider
http://sqlalchemy-media.dobisel.com/tutorials/image.html#defining-the-model,
where the Person class contains an "image" column defined approximately as

  class Person(Base):
     ...
     image = Column(Image.as_mutable(Json))
     
Inspecting the class, I find that the "type" of the image column is actually
"Json", so that alone does not help. I tried different strategies, but I could
not find a way to determine it is related to "Image".

Basically, in pseudo code, I'd like to distill an helper function like

  def find_image_columns(base_class):
      for cls in base_class.__subclasses__():
          m = class_mapper(cls)
          for col in m.columns:
              if <col is related to Image>:  # this is my glass of water
                  yield cls, col
                  
I followed the as_mutable() code path, and found that it installs various
"hooks" to achieve its goal, but could not figure out how I could "inspect"
those to find out the link with the Image class.

As a last resort, I can easily go around all my models and put some kind of a
marker in the "info" slot of the relevant columns, and then check for that,
but I wonder if there is an less intrusive way... knowing and loving SA I bet
there is and it's just a matter of pronouncing the right incantation :-)

Thank you in advance for any hint,
ciao, lele.
-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
l...@metapensiero.it  |                 -- Fortunato Depero, 1929.

-- 
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 post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/87lfx6pd8n.fsf%40metapensiero.it.
For more options, visit https://groups.google.com/d/optout.

Reply via email to