The new Entity.set in Elixir 0.6 breaks some of my projects.
In 0.5.2, the __init__ and .set methods performed the same function:
for key, value in kwargs.items():
setattr(self, key, value)
My first question is, why didn't __init__() just call set()? Were you
looking forward to the changes in 0.6? Even in 0.6, should __init__
just call set()? Perhaps the answer lies in my second question.
Beginning with 0.6, set does something different. It attempts to
reassemble an object from a JSON-generated structure:
def set(self, **kwargs):
self.from_dict(kwargs)
Unfortunately, the from_dict method fails to set properties who's
property name does not match the column name:
class Attribute(Entity):
key = Field(String(256), colname='attribute_key')
new_attr = Attribute()
new_attr.set(key='foo') # fails to set key beginning in 0.6.
Perhaps to_dict and from_dict could be kept independent of .set,
maintaining backward compatibility.
Furthermore, I'm unsure the motivation for using column names instead
of entity properties, but I would suggest even using entity properties
for generating the JSON dicts. I'm not sure if this is feasible, but
from my perspective, one of the primary advantages of Elixir/
SQLAlchemy is that it abstracts underlying details such as the column
names so that more appropriate and consistent names can be used in the
application. The to/from_dict methods violate this abstraction, and I
believe that is why my app fails.
Is there perhaps a better way to implement the to/from_dict methods to
(a) better handle properties whose names differ from the column names
and (b) allow set to be backward compatible with 0.5?
I wanted to start with the discussion here. Let me know if I should
post any of these in the trac ticket system.
Regards,
Jason
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"SQLElixir" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sqlelixir?hl=en
-~----------~----~----~----~------~----~------~--~---