1. Michael Bayer
  2. sqlalchemy
  3. Issues


Issue #2642 new

try to add a real "replace collection" to association proxy

Michael Bayer
repo owner created an issue

the "clear" here is clumsy and originally thought was the ultimate cause of the original issue in #2637 it's not. Might be nicer if we had a bulk replace built in for those collections, would emit fewer events.

    def __set__(self, obj, values):
        if self.owning_class is None:
            self.owning_class = type(obj)

        if self.scalar:
            creator = self.creator and self.creator or self.target_class
            target = getattr(obj, self.target_collection)
            if target is None:
                setattr(obj, self.target_collection, creator(values))
                self._scalar_set(target, values)
            proxy = self.__get__(obj, None)
            if proxy is not values:
                self._set(proxy, values)

Comments (7)

  1. Log in to comment