V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
node
V2EX  ›  Python

有点看不太懂 SQLAlchemy 的 relationship

  •  
  •   node · Apr 7, 2013 · 4020 views
    This topic created in 4768 days ago, the information mentioned may be changed or developed.
    比如这段v0.8的官方的example:
    https://gist.github.com/anonymous/5329921

    OrderItem.order_id 是指向 Order 的外键,但 Order.order_items 右边的 relationship 的参数里没出现 OrderItem.order_id ,那 Order.order_items 这个反向引用是怎么知道要的数组是所有 OrderItem.order_id 等于自己的那些 OrderItem 呢?假如 OrderItem 里还有个 another_order_id 也是指向 Order 的外键,又该怎么破?
    2 replies    1970-01-01 08:00:00 +08:00
    leojoy710
        1
    leojoy710  
       Apr 7, 2013
    another_order_id -> another_order_items ?
    node
        2
    node  
    OP
       Apr 7, 2013
    你的意思是sqlalchemy在玩string游戏?即便是这样 order_items 和 OrderItem 的字面关系也就是去掉 s 再改成大写开头,从逻辑上来讲肯定不会对应出 another_order_items 的(这个example的变量取名有点乱)
    另外官方文档还有个 User 和 Address 的例子,User 有个叫 addresses 的反向 relationship ,玩string的话不会强悍到连后面加s还是es都能搞的定吧
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5582 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 07:26 · PVG 15:26 · LAX 00:26 · JFK 03:26
    ♥ Do have faith in what you're doing.