Hi Mike,
What if during reconstruction you need a one-to-many attribute, like:
class Planning(SqlaBase):
stops = relationship("Stop", back_populates="planning", lazy="joined")
matrix_factory = Matrix
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.matrix = self.matrix_factory(self.stops)
@reconstructor
def init_on_load(self):
self.matrix = self.matrix_factory(self.stops)
The docs say self.stops will not be completely loaded in init_on_load, how
could i make this work?
Cheers, Lars
On Monday, August 7, 2017 at 6:09:08 AM UTC+2 Mike Bayer wrote:
>
>
> On Aug 6, 2017 1:33 PM, "Shane Carey" <[email protected]> wrote:
>
> Hey Mike,
>
> I can expand my example. I have an orm mapped attribute like this
>
> class Obj(Base):
> _evaluator = Column(String)
>
> def __init__(self, **kwargs):
> super().__init__(**kwargs)
> self._eval_func = eval(self._evaluator)
>
> @orm.reconstructor
> def init_on_load(self):
> self._eval_func = eval(self._evaluator)
>
> @property
> def evaluator(self):
> return self._eval_func
>
> @evaluator.setter
> def set_evaluator(ev):
> self._evaluator = ev
> self._eval_func = eval(self._evaluator)
>
> You can see that I have to explicitly set self._eval_func in three
> different places, when really I just want to set it every time
> self._evaluator is set.
>
> It looks to me like the orm events are just a different way of placing the
> different settings of this class attribute
>
> Also, I would like to not call eval in the getter of the property for the
> sake of performance (I know that would simplify the issue).
>
> Is there a way to intercept the setting of self._evaluator for all cases?
>
>
>
> Use the init and load event listeners from my previous email on top of one
> function. It will be called for init and load.
>
>
> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.
>
>
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/sqlalchemy/e9b2b9ff-0979-43be-94f4-fdb3ceb48ae9n%40googlegroups.com.