如何使用cakePHP在我的模型中创建内部联接?
我的模型是'Apertura',有许多'AperturaArticulo',但当我调用它时,我从AperturaArticulo获得下一个字段: id |价格|总额|创建|修改|艺术id 我想通过articulo.description更改articulo_id,因此我需要一个内部联接,但我不知道如何进行 这是我的密码:如何使用cakePHP在我的模型中创建内部联接?,php,mysql,cakephp,Php,Mysql,Cakephp,我的模型是'Apertura',有许多'AperturaArticulo',但当我调用它时,我从AperturaArticulo获得下一个字段: id |价格|总额|创建|修改|艺术id 我想通过articulo.description更改articulo_id,因此我需要一个内部联接,但我不知道如何进行 这是我的密码: public $hasMany = array( 'AperturaArticulo' => array( 'className' => '
public $hasMany = array(
'AperturaArticulo' => array(
'className' => 'AperturaArticulo',
'foreignKey' => 'apertura_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
)
);
我希望你能帮助我
更新:
1我有一个视图,其中我从名为“Apertura”的模型中调用“Aperturaticulo”,我有下一个表:。在我看来,使用下一个代码:
<?php if (!empty($apertura['AperturaArticulo'])): ?>
<table cellpadding = "0" cellspacing = "0">
<tr>
<th><?php echo __('Articulo'); ?></th>
<th><?php echo __('Cantidad'); ?></th>
<th><?php echo __('Precio'); ?></th>
<th><?php echo __('Total'); ?></th>
<th><?php echo __('Fecha de alta'); ?></th>
<th><?php echo __('Última modificación'); ?></th>
<th class="actions"><?php echo __('Acciones'); ?></th>
</tr>
<?php foreach ($apertura['AperturaArticulo'] as $aperturaArticulo): ?>
<tr>
<td><?php echo $aperturaArticulo['articulo_id']; ?></td>
<td><?php echo $aperturaArticulo['cantidad']; ?></td>
<td><?php echo $aperturaArticulo['precio']; ?></td>
<td><?php echo $aperturaArticulo['total']; ?></td>
<td><?php echo $aperturaArticulo['created']; ?></td>
<td><?php echo $aperturaArticulo['modified']; ?></td>
<td class="actions">
<?php echo $this->Html->link(__('View'), array('controller' => 'apertura_articulos', 'action' => 'view', $aperturaArticulo['id'])); ?>
<?php echo $this->Html->link(__('Edit'), array('controller' => 'apertura_articulos', 'action' => 'edit', $aperturaArticulo['id'])); ?>
<?php echo $this->Form->postLink(__('Delete'), array('controller' => 'apertura_articulos', 'action' => 'delete', $aperturaArticulo['id']), array(), __('Are you sure you want to delete # %s?', $aperturaArticulo['id'])); ?>
</td>
</tr>
<?php endforeach; ?>
</table>
在第一行中,您可以看到$apertura[aperturacticulo]$apertura是我的模型,[Aperturarticulo]是我模型中的多个关系
2如果您在表格中看到,请在第一列显示数字。这些数字是一个名为“AperturaArticulo”的表的字段“articulo_id”
3这些协会是:
“apertura_id”是外键,因此在表中只显示“AperturaArticulos”,其中apertura_id=n
在我的数据库中,我有3个表
“开孔器”->id |供应商id |车辆id |观察者|创建|修改
“apertura_articulos”->id | tipo | apertura_id | articulo|u id | cantidad | precio | total |创建|修改
“articulos”->id | codigo | u articulo | Description | unidad | precio | activo | articulo | u grupo | marca | existencia | proveedor | id |创建|修改
在我的“Apertura”模型中,我有一个关系,其中一个Apertura有许多Apertura关节
但我想要的只是在关节孔和关节孔之间的内部连接。就这样。谢谢你 你这样说是什么意思:1但是当我称之为——你实际上在做什么?2我想通过articulo.description更改articulo_id-您所说的更改是什么意思?3什么是articulo_id?-在你的代码中,你有apertura_id。你能为你的AperturaArticulo模型提供关联吗?我已经更新了信息。我希望它有用。