Re: [Sqlalchemy-tickets] [sqlalchemy] #2808: AssociationProxy should use keywords on create
Brought to you by:
zzzeek
|
From: sqlalchemy <mi...@zz...> - 2013-08-26 15:13:47
|
#2808: AssociationProxy should use keywords on create
-----------------------------------+----------------------------------
Reporter: schlamar | Owner: zzzeek
Type: enhancement | Status: reopened
Priority: medium | Milestone: 0.8.xx
Component: ext | Severity: minor - half an hour
Resolution: | Keywords:
Progress State: completed/closed |
-----------------------------------+----------------------------------
Comment (by zzzeek):
Replying to [comment:10 schlamar]:
> I think this is rather a workaround than a solution in case of an
association object because it is really unintuitive.
>
> From a user point of view the "association proxy" pattern shouldn't be
this complex. Essentially you say: proxy this attribute as a collection
via a many-to-many mapping. When a user pass an object to this collection,
SQLAlchemy should know how to build the many-to-many relationship without
requiring manual configuration from the user.
The reason we don't do things like that is because the user sees it as
"magic", and when things go wrong, even simple things, they have
absolutely no idea where to look. A many-to-many mapping has lots of
options - the secondary table, the join condition, backrefs, it has an
attribute name of its own, the user needs to specify these things
explicitly.
The reason SQLAlchemy's patterns are so explicit is because they get
intricate really fast, and we prefer the user to work out the individual
links in the chain. There are always ways to automate these patterns,
so the issue is not "too much typing" - you can automate that.
If you want to see the opposite, look at sqlalchemy-elixir, which hides
everything and creates attribute names and all that behind the scenes.
When something goes wrong with that, the user is lost. Hence
declarative's explicit approach has proven to be more popular.
>
> So IMO the creation process in case of an association object should
behave something like this (with !User/Keyword example)
>
> {{{
> #!python
>
> def _create(keyword):
> # create association object (UserKeyword)
> # do not pass the value (or pass the value
> # but the default creator shouldn't pass it
> # further to UserKeyword)
> uk = self.creator()
> # automatically find out how Keyword is related with
> # UserKeyword and set the correct attribute
> uk.find_relationship_and_set(keyword)
>
> }}}
This is possible for simple cases but then is not feasible for complex
cases, so as the scenario grows more complex, the easy magic starts to
make mistakes and we get bug reports. It's better to ask the user to
explicitly tell us what to do rather than guessing.
--
Ticket URL: <http://www.sqlalchemy.org/trac/ticket/2808#comment:12>
sqlalchemy <http://www.sqlalchemy.org/>
The Database Toolkit for Python
|