> > Please understand that synonym() is mostly an obsolete feature, that >
ok, I did not realize this. I'm sorry it wasn't clear that I was misusing a feature that was meant to not be used. I found it by scanning docs and just thought it did what I wanted. again this is very old documentation around a parameter that is > obsolete within a feature that is itself seldom used, as it has been > superseded by other approaches. The map_column parameter is also > I didn't mean to force usage of synonym. I simply meant to ask how to accomplish what I wanted with what I thought the available tools were. Sorry for the confusion. > The hybrid_property is the modern way to achieve this, however if you > Thanks for the pointer, I will explore hybrid_property then. > The Column must still be mapped to a name and this must be done > explicitly in some way - the map_column parameter was a shortcut that > worked with classical mappings, because it would locate the > table-bound Column of the given name and then automatically map it to > the stated "name" of the synonym. This cannot work with Declarative > as implemented because Declarative will fail to map the Column at all > when the attribute which names it is replaced. This is simple Python: > > > class MyClass(object): > my_attribute = "one" > > my_attribute = "two" > > > Above, MyClass.my_attribute is named "two". The value "one" is gone. > Declarative uses metaclasses in order to intercept the creation of > the class, which means it is given a dictionary of names that are > associated with the class. For a class as above, it will see exactly > one key/value, that is "my_attribute = 'two'". Declarative will never > see "one" at all and have no chance to act upon it. So in your > example: > > class MyClass(Base): > __tablename__ = 'my_table' > id = Column(Integer, primary_key=True) > job_status = Column(String(50)) > job_status = synonym("_job_status", map_column=True) > > the Column above will never be seen by Declarative and is discarded by > the Python interpreter immediately. Please use this as evidence (in > addition to the author of said feature and said documentation telling > you that the feature never worked this way) that the feature cannot > even hypothetically work in the way you describe. > > I apologize for the confusion. I believed that this would be possible based on my cursory understanding of how the python Enum class behaves. But I didn't realize that it is allowed to work because of additional functionality provided in python 3. (Enums can detect duplicate members and throw). This is apparently the source of my confusion which led me down this rabbit hole in the first place. I did not mean to question your knowledge of the system, but rather point out that the documentation combined with my misunderstanding of python 2/3 differences led me to believe that the functionality would have been intended. > > > > The section of the docs that I linked to > > seem to explicitly state that it should work that way. Maybe I'm > > misunderstanding what the docs mean, but the text seems to be clearly > > indicating that what I'm asking should be possible, and even indicates > what > > a typical use would be. > > Please note that I am the author of this documentation and the creator > of this functionality. It is very old and was inaccurately written > back before Declarative existed. > > I understand that you are the author, and it seems I expressed a message that I didn't intend. Rather than questioning whether the functionality actually existed, I was pointing out that the documentation led me here because I wanted it to work the way I understood the documentation. I wasn't meaning to say, "You're wrong because the documentation says so". You also questioned what my intent was, and since the documentation seemed to express what I wanted, I quoted it. It seems the disconnect was that you knew this couldn't exist in python 2, and assumed I also knew that until your recent post. I'll try to be more careful next time. I understand now that the documentation was old and from before Declarative existed, but since the sample was in the Declarative style, it wasn't obvious to me before I started down this path. Thank you for your patience and help. -- 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. For more options, visit https://groups.google.com/d/optout.