Ticket #47 (closed defect: fixed)
Entity.set to/from_dict
| Reported by: | guest | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | 0.6 |
| Component: | core | Version: | |
| Keywords: | Entity set from_dict | Cc: | jaraco@… |
Description
Reposted from discussion http://groups.google.com/group/sqlelixir/browse_thread/thread/947e4eac58490718 .
Beginning with 0.6, Entity.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?
