假设我有几个对象,有一对多的关系,就像
class Parent():
//id, other cols, etc
children = relationship("Child", backref="parent")
class Child():
parent_id = Column(Integer, ForeignKey("parent.id")
child_type = Column(Enum("a","b"))
Run Code Online (Sandbox Code Playgroud)
现在,我想查询Parent对象,但让他们的子进程按child_type进行过滤,即类似
session.query(Parent).join(Parent.children).filter(Child.child_type == "a")
Run Code Online (Sandbox Code Playgroud)
这只会返回所有子节点的Parent,基本上忽略了过滤器.这个结果是否可能,或者我是否还要查询Child?
我已经尝试了无数的解决方案,似乎没有任何工作.我正在尝试安装mysql-python,但这种情况发生在numpy和其他需要gcc的包中:
building '_mysql' extension
gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -isysroot /Developer/SDKs/MacOSX10.6.sdk -g -O2 -DNDEBUG -g -O3 -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/local/mysql/include -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mysql.c -o build/temp.macosx-10.6-intel-2.7/_mysql.o -Os -g -fno-strict-aliasing -arch x86_64
In file included from _mysql.c:29:
/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h:33:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
^
1 error generated.
error: command 'gcc-4.2' failed with exit status 1
Run Code Online (Sandbox Code Playgroud)
指出:
我已经安装了命令行工具
从/ usr/bin/gcc添加符号链接到/usr/bin/gcc-4.2
gcc-4.2 --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.1.0
Thread model: posix
Run Code Online (Sandbox Code Playgroud)
创建了一个虚拟的c文件,成功编译并运行它,所以gcc本身就没问题
$ …Run Code Online (Sandbox Code Playgroud) 我正在尝试将我之前在Perl脚本中设置的变量设置为环境变量,但似乎没有意识到我传入的参数是变量而不是我想要的实际路径.
例如,当我运行这个时:
$ENV{'ENV_VARIABLE'}='\'$file_path\'';
print($ENV{'ENV_VARIABLE'});
Run Code Online (Sandbox Code Playgroud)
我只得到:
'$file_path'
Run Code Online (Sandbox Code Playgroud)
有什么方法可以告诉我,我传入的内容实际上是一个变量而不是文字字符串?
python ×2
filtering ×1
gcc ×1
macos ×1
mysql-python ×1
numpy ×1
one-to-many ×1
orm ×1
perl ×1
sqlalchemy ×1