Is there documentation/tutorials/recipes somewhere about how to
properly use SA from TurboGears?
The problem I'm hitting at the moment is how to properly select simple
objects... There seems to be two main approaches, for example:
session.query(Ownership).select() or
ownership_table.select().execute()
With the first approach, I get
InvalidRequestError: Parent instance <class 'tnf.model.Ownership'> is
not bound to a Session, and no contextual session is established; ...
which I'm not sure how tackle - there's no mention I can find of when
and where create_session should be called...
The the second approach, the SELECTs work fine, but then I'm working
with RoxProxy objects, rather than my models, which don't have the
relations and back-references I've set up and that I obviously need.
Can anyone answer these specific questions or point me in the
direction of some further documentation?
Thanks,
James
> The problem I'm hitting at the moment is how to properly select simple
> objects... There seems to be two main approaches, for example:
> session.query(Ownership).select() or
> ownership_table.select().execute()
>
> With the first approach, I get
> InvalidRequestError: Parent instance <class 'tnf.model.Ownership'> is
> not bound to a Session, and no contextual session is established; ...
> which I'm not sure how tackle - there's no mention I can find of when
> and where create_session should be called...
>
Did you call assign_mapper on Ownership?
> Can anyone answer these specific questions or point me in the
> direction of some further documentation?
>
You should be able to call Ownership.query() just fine, if you have a
working mapper.
Read over these examples. Hopefully that answers your question.
> session.query(Ownership).select() or
http://lucasmanual.com/mywiki/TurboGears#head-6f83a62f8c04cde09ea95b375a4041ce0817c661
> ownership_table.select().execute()
http://lucasmanual.com/mywiki/TurboGears#head-eb3ffb8d71d898537ec2538152d00dd243d5241e
>
> With the first approach, I get
> InvalidRequestError: Parent instance <class 'tnf.model.Ownership'> is
> not bound to a Session, and no contextual session is established; ...
> which I'm not sure how tackle - there's no mention I can find of when
> and where create_session should be called...
>
> The the second approach, the SELECTs work fine, but then I'm working
> with RoxProxy objects, rather than my models, which don't have the
> relations and back-references I've set up and that I obviously need.
>
> Can anyone answer these specific questions or point me in the
> direction of some further documentation?
>
> Thanks,
> James
>
>
> >
>
--
--
TurboGears from start to finish:
http://www.lucasmanual.com/mywiki/TurboGears
Hi Ruben,
I'm actually using version 0.3, so hadn't seen that tutorial - that is
the sort of thing I was looking for! To be honest, the hole in
documentation seems to be on the TurboGears side, which currently has
a lot more on SQLObject...
So it seems from that tutorial that session.query... is the way to go
for these selects, and I need to learn how to manage the sessions
properly!
Thanks,
James
Hi Marco, assign_mapper did help - the relations are now accessible
through my models, and the query syntax is nicer than pure SA as well
in my opinion.
However, I'm using the identity framework (part of TurboGears) which
unfortunately doesn't play nicely with assign_mapper... shame!
James
> Hi Marco, assign_mapper did help - the relations are now accessible
> through my models, and the query syntax is nicer than pure SA as well
> in my opinion.
>
> However, I'm using the identity framework (part of TurboGears)
Me too.
> which unfortunately doesn't play nicely with assign_mapper... shame!
>
What do you mean?
[...]
>
> However, I'm using the identity framework (part of TurboGears) which
> unfortunately doesn't play nicely with assign_mapper... shame!
>
If you use SA 0.3.10 I would advise you to use mapper (from
sqlalchemy.orm import mapper) instead of assign_mapper.
If you could send a post in the TurboGears mailing list about why
identity does not play nice with assign_mapper we would surely find a
solution to your issue :)
I used a lot of assign_mapper myself with TG a few months back, I now
switched to mapper in order to become 0.4 compliant, but I can tell
you TG 1.0.2/1.0.3.x are assign_mapper friendly... 1.0.4beta1 should
also be usable with assign_mapper.
Regards,
Florent.
On Oct 11, 1:01 pm, "Florent Aide" <florent.a...@gmail.com> wrote:
> On 10/11/07, James Brady <james.colin.br...@gmail.com> wrote:
>
> > > Did you call assign_mapper on Ownership?
>
> [...]
>
> > However, I'm using the identity framework (part of TurboGears) which
> > unfortunately doesn't play nicely with assign_mapper... shame!
>
> If you use SA 0.3.10 I would advise you to use mapper (from
> sqlalchemy.orm import mapper) instead of assign_mapper.
> If you could send a post in the TurboGears mailing list about why
> identity does not play nice with assign_mapper we would surely find a
> solution to your issue :)
So, using mapper rather than assign_mapper brings me back to my
original problem of not being able to use the relations I've set up in
my models - the ResultProxy object only has the basic keys from the
table definition.
> I used a lot of assign_mapper myself with TG a few months back, I now
> switched to mapper in order to become 0.4 compliant, but I can tell
> you TG 1.0.2/1.0.3.x are assign_mapper friendly... 1.0.4beta1 should
> also be usable with assign_mapper.
So is assign_mapper deprecated in SA 0.4? Is sqlalchemy.orm.mapper the
direction I should be heading in?
Thanks,
James