我有两个型号:Product和MBiopoint。 它们通过名为t_Dataset_Data的多对多表相关联。在Product表中,有一个属性'data'声明如下:
@Override
protected void onCreate(Bundle savedInstanceState) {
//call the method in the super class..
super.onCreate(savedInstanceState);
//inflate the xml layout.
setContentView(R.layout.main);
//prepare buttons.
ImageButton startButton = (ImageButton) findViewById(R.id.start_btn);
ImageButton stopButton = (ImageButton) findViewById(R.id.stop_btn);
//prepare service intent:
final Intent serviceIntent = new Intent(getApplicationContext(), BackgroundService.class);
//set on click listeners for buttons (this should respond to normal touch events and simulated ones):
startButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//startActivity(serviceIntent);
//start eye gazing mode as a service running in the background:
isBound= getApplicationContext().bindService(serviceIntent, mConnection, Context.BIND_AUTO_CREATE);
}
});
stopButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//stop eye gazing mode as a service running in the background:
getApplicationContext().unbindService(mConnection);
}
});
}//end onCreate.
private final ServiceConnection mConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName className, IBinder service) {
BackgroundService.LocalBinder binder = (BackgroundService.LocalBinder) service;
mService = binder.getService();
isBound = true;
}
@Override
public void onServiceDisconnected(ComponentName className) {
isBound = false;
}
};
因此,当我在Product表中查询这样的特定产品时:
data = relationship(u'MBiopoint', secondary=t_Dataset_Data)
我现在可以访问所有与我的产品在多对多表中关联的MBiopoint记录,例如通过此代码(访问MBiopoint的datastatus列的值):
prod = session.query(Product).filter_by(product_id=69).first()
我现在需要的是在不使用for循环的情况下获取与我的产品相关的所有数据记录的'datastatus'列的不同值,如下所示:for pd in prod.data:
print pd.datastatus
答案 0 :(得分:1)
使用freenode Web IRC网络聊天,用户的昵称为#agronholm'为我的问题提供了解决方案。 他的建议是:
set(pd.datastatus for pd in prod.data)
或以现代方式:
{pd.datastatus for pd in prod.data}
这对我有用。