我有一个订单表,有30多列。我想在attribute
表中显示除orders
列以外的所有列。
我们都知道要从表中选择特定id的所有列,我们可以使用
$data = $this->Order->find('first', array('conditions'=>array('Order.id'=>1)));
您能否告诉我如何在CakePHP 2.x中编写查询?
答案 0 :(得分:2)
我怀疑通过从查询中排除列来获得更多收益。如果您确实需要这样做,那么您可以获取model's schema,然后从中删除该列,然后通过定义查询返回的字段来使用find()
中的其余列: - < / p>
// Get the model’s schema.
$schema = $this->Order->schema();
// Remove the `attribute` column from the schema.
unset($schema['attribute']);
// Determine the remaining columns from the schema.
$cols = array_keys($schema);
// Now call your query specifying the fields you want back using the
// columns we’ve just determined.
$data = $this->Order->find('first',
array(
'fields' => $cols,
'conditions' => array('Order.id' => 1)
)
);
答案 1 :(得分:1)
您应该在{}使用getColumnTypes():
// Create the constraint in code
NSLayoutConstraint *constraint0 = [NSLayoutConstraint constraintWithItem: myImage attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeWidth multiplier:1.0f constant: yourNewsWidth];
NSLayoutConstraint *constraint1 = [NSLayoutConstraint constraintWithItem: myImage attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeHeight multiplier:1.0f constant: yourNewsHeight];
[myImage addConstraint:constraint0];
[myImage addConstraint:constraint1];