0
我試圖通過查找表獲取與父對象關聯的所有記錄,並將它們直接插入到模型中。我有一個對象,角色,hasMany()RoleEndpoints。 RoleEndpoints屬於角色和hasMany()端點。所有的數據都按照我的預期進行檢索,但是,在我設置它後,它似乎消失了。成功設置其他屬性後消失
<?php
class ACL {
private $_di;
public function __construct($di) {
$this->_di = $di;
}
public function createACL() {
if(!$this->_acl) {
$this->_acl = new stdClass();
$roles = $possibleRoles = Roles::find();
/**
* Check if there is at least one role out there
*/
if($roles->count() > 0) {
/**
* Iterate over all of the records
*/
while($roles->valid()) {
$endpoints = array();
/**
* Grab each role's endpoints through the relationship
*/
foreach($roles->current()->getRoleEndpoints() as $roleEndpoint) {
$endpoints[] = Endpoints::findFirst($roleEndpoint->endpoint_id);
}
/**
* At this point, the endpoints exist in the current Role model;
I tried several different approaches; this seemed the best
*/
$roles->current()->endpoints = $endpoints;
}
/**
* Set object to loop through from the beginning
*/
$roles->rewind();
/**
* Here is where my issue lies.
*
* The endpoints attribute, which is set as a public attribute in the model class
* gets unset for some reason
*/
while($roles->valid()) {
echo '<pre>';
var_dump($roles->current());
exit;
}
正如註釋所述,在結果集的第二次迭代期間,由於某種原因,端點屬性drop將變爲null。我在這裏做錯了什麼?我錯過了一步嗎?
任何幫助,將不勝感激。謝謝!
我結束了最後的解決方案,其中該邏輯是在模型中去。我要把這個報告給Phalcon的開發者,因爲我不明白爲什麼設置的屬性會消失。謝謝你的幫助! –