gpt4 book ai didi

php - 蛋糕PHP 3 : how to get all associations of a table?

转载 作者:行者123 更新时间:2023-12-04 13:04:18 27 4
gpt4 key购买 nike

那是我的表对象的 var_dump():

object(App\Model\Table\BairrosTable)[117]
public 'registryAlias' => string 'Bairros' (length=7)
public 'table' => string 'bairros' (length=7)
public 'alias' => string 'Bairros' (length=7)
public 'entityClass' => string 'App\Model\Entity\Bairro' (length=23)
public 'associations' =>
array (size=4)
0 => string 'regioes' (length=7)
1 => string 'cidades' (length=7)
2 => string 'clientes' (length=8)
3 => string 'areas' (length=5)
public 'behaviors' =>
array (size=0)
empty
public 'defaultConnection' => string 'default' (length=7)
public 'connectionName' => string 'default' (length=7)

我只想获取属性关联的数组,但是如果我尝试 $this->_table()->associations() ,我在 protected 变量上得到了一个带有 itens 的对象:
object(Cake\ORM\AssociationCollection)[205]
protected '_items' =>
array (size=4)
'regioes' =>
object(Cake\ORM\Association\BelongsTo)[206]
protected '_validStrategies' =>
array (size=2)
...
protected '_name' => string 'Regioes' (length=7)
protected '_className' => null
protected '_bindingKey' => null
protected '_foreignKey' => string 'regiao_id' (length=9)
protected '_conditions' =>
array (size=0)
...
protected '_dependent' => boolean false
protected '_cascadeCallbacks' => boolean false
protected '_sourceTable' =>
object(App\Model\Table\BairrosTable)[117]
...
protected '_targetTable' => null
protected '_joinType' => string 'INNER' (length=5)
protected '_propertyName' => null
protected '_strategy' => string 'join' (length=4)
protected '_finder' => string 'all' (length=3)
protected '_tableLocator' => null
'cidades' =>
object(Cake\ORM\Association\BelongsTo)[193]
protected '_validStrategies' =>
array (size=2)
...
protected '_name' => string 'Cidades' (length=7)
protected '_className' => null
protected '_bindingKey' => null
protected '_foreignKey' => string 'cidade_id' (length=9)
protected '_conditions' =>
array (size=0)
...
protected '_dependent' => boolean false
protected '_cascadeCallbacks' => boolean false
protected '_sourceTable' =>
object(App\Model\Table\BairrosTable)[117]
...
protected '_targetTable' => null
protected '_joinType' => string 'INNER' (length=5)
protected '_propertyName' => null
protected '_strategy' => string 'join' (length=4)
protected '_finder' => string 'all' (length=3)
protected '_tableLocator' => null
'clientes' =>
object(Cake\ORM\Association\HasMany)[200]
protected '_joinType' => string 'INNER' (length=5)
protected '_strategy' => string 'select' (length=6)
protected '_validStrategies' =>
array (size=2)
...
protected '_saveStrategy' => string 'append' (length=6)
protected '_name' => string 'Clientes' (length=8)
protected '_className' => null
protected '_bindingKey' => null
protected '_foreignKey' => string 'bairro_id' (length=9)
protected '_conditions' =>
array (size=0)
...
protected '_dependent' => boolean false
protected '_cascadeCallbacks' => boolean false
protected '_sourceTable' =>
object(App\Model\Table\BairrosTable)[117]
...
protected '_targetTable' => null
protected '_propertyName' => null
protected '_finder' => string 'all' (length=3)
protected '_tableLocator' => null
protected '_sort' => null
'areas' =>
object(Cake\ORM\Association\BelongsToMany)[199]
protected '_joinType' => string 'INNER' (length=5)
protected '_strategy' => string 'select' (length=6)
protected '_junctionTable' => null
protected '_junctionTableName' => string 'areas_bairros' (length=13)
protected '_junctionAssociationName' => null
protected '_junctionProperty' => string '_joinData' (length=9)
protected '_saveStrategy' => string 'replace' (length=7)
protected '_targetForeignKey' => string 'area_id' (length=7)
protected '_through' => null
protected '_validStrategies' =>
array (size=2)
...
protected '_dependent' => boolean true
protected '_targetConditions' => null
protected '_junctionConditions' => null
protected '_name' => string 'Areas' (length=5)
protected '_className' => null
protected '_bindingKey' => null
protected '_foreignKey' => string 'bairro_id' (length=9)
protected '_conditions' =>
array (size=0)
...
protected '_cascadeCallbacks' => boolean false
protected '_sourceTable' =>
object(App\Model\Table\BairrosTable)[117]
...
protected '_targetTable' => null
protected '_propertyName' => null
protected '_finder' => string 'all' (length=3)
protected '_tableLocator' => null
protected '_sort' => null

那么,如何获得一个包含表的所有关联的数组?

最佳答案

解决了。 $this->_table()->associations()\Cake\ORM\AssociationCollection目的。所以我使用 keys()获取关联数组的方法。

关于php - 蛋糕PHP 3 : how to get all associations of a table?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41246289/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com