V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2013-04-07 18:49:54 +08:00 · 3170 次点击
    这是一个创建于 4039 天前的主题,其中的信息可能已经有所发展或是发生改变。
    比如这段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 条回复    1970-01-01 08:00:00 +08:00
    leojoy710
        1
    leojoy710  
       2013-04-07 18:59:59 +08:00
    another_order_id -> another_order_items ?
    node
        2
    node  
    OP
       2013-04-07 20:32:48 +08:00
    你的意思是sqlalchemy在玩string游戏?即便是这样 order_items 和 OrderItem 的字面关系也就是去掉 s 再改成大写开头,从逻辑上来讲肯定不会对应出 another_order_items 的(这个example的变量取名有点乱)
    另外官方文档还有个 User 和 Address 的例子,User 有个叫 addresses 的反向 relationship ,玩string的话不会强悍到连后面加s还是es都能搞的定吧
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4512 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 04:04 · PVG 12:04 · LAX 21:04 · JFK 00:04
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.