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.
le...@metapensiero.it | -- Fortunato Depero, 1929.