On 8/28/15 3:51 AM, [email protected] wrote:
I now have a code that seems to work, but I'm not sure I did it right :
|
Base=automap_base()
classDispositif(Base):
__tablename__ ='dispositifs'
hardwares =association_proxy('disp_hdw_collection','hardware_ref')
classHardware(Base):
__tablename__ ='hardware'
Base.prepare(engine,reflect=True)
|
sure, it's all about the names you've configured your automap_base() to
use, which in this case would be the defaults.
Another question is why sqlalchemy produce two queries to get
hardwares collections from a dispositif :
|
>>>some_disp.hardwares
2015-08-2810:36:41,722INFO sqlalchemy.engine.base.EngineSELECT
disp_hdw.iddispositif AS disp_hdw_iddispositif,disp_hdw.idhardware AS
disp_hdw_idhardware,disp_hdw.instance AS disp_hdw_instance
FROM disp_hdw
WHERE %s =disp_hdw.iddispositif
2015-08-2810:36:41,725INFO sqlalchemy.engine.base.Engine(2721L,)
2015-08-2810:36:41,768INFO sqlalchemy.engine.base.EngineSELECT
hardware.hdw_type AS hardware_hdw_type,hardware.id AS
hardware_id,hardware.idbox AS hardware_idbox
FROM hardware
WHERE hardware.id =%s
2015-08-2810:36:41,772INFO sqlalchemy.engine.base.Engine(268L,)
|
There's no context given here, but that would indicate that the
"some_disp" instance has been expired. When you .commit() a session,
all objects are expired by default. This is so that if, when you next
operate on the objects, some other transaction has deleted that row, the
session can let you know that you're working on stale data. See the
session docs for options on how to control this behavior.
instead of somewhat like :
|
SELECT hardware.hdw_type AS hardware_hdw_type,hardware.id AS
hardware_id,hardware.idbox AS hardware_idbox
FROM hardware
JOIN disp_hdw ON hardware.id =disp_hdw.idhardware
WHERE disp_hdw.iddispositif =%s
|
Le vendredi 28 août 2015 10:20:55 UTC+3, [email protected] a écrit :
Hello,
I want to use assocation proxy pattern
<http://docs.sqlalchemy.org/en/latest/orm/extensions/associationproxy.html>
with automap. I tried this code :
|
Base=automap_base()
classDispositif(Base):
__tablename__ ='dispositifs'
hardwares =association_proxy('disp_hardwares','hardware')
classHardware(Base):
__tablename__ ='hardware'
Base.prepare(engine,reflect=True)
|
but it does not work.
Any help appreciated.
Best regards
--
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]
<mailto:[email protected]>.
To post to this group, send email to [email protected]
<mailto:[email protected]>.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
--
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 http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.