If looping the results start becoming too slow for you, you can force Cake to do a join which will make the whole result disappear if the Post is empty.
Nate wrote about it and inspired me to build my own variation. http://bakery.cakephp.org/articles/view/quick-tip-doing-ad-hoc-joins-in-model-find My take on it was to make the syntax as close to Containable as I could. I pasted some code into the bin for anyone who wants a peek. Feel free to make use of it... if it works for you. I have only tested it in a very limited way and do not use it that much. http://bin.cakephp.org/view/992365224 On Aug 11, 5:44 am, joshua <[email protected]> wrote: > I think you can define a model level filter, it will help you to solve this > problem thoroughly. Just an idea of mine. Maybe you can put the filter > engine in AppModel.[Client] ----> {Filter engine} ----> [Server] > [Client] <--- {Filter engine} <---- [Server] > > For a temporary solution, I think the loop is enough: > Assume the return result something like this: > > [0] => Array > ( > [Bookmark] => Array > ( > [id] => 38b7276f708 > [user_id] => 4a5d569f-b9e8-416d-b34c-11cf4adcd75b > [post_id] => 11e7ee > [created] => 2009-08-09 21:59:01 > ) > > [Post] => Array > ( > [title] => Test Title > [rank] => 2 > [created] => > [description] => Test dscription > [id] => 52louj > > ) > > ) > [1] => Array > ( > [Bookmark] => Array > ( > [id] => 38b7276f708 > [user_id] => 4a5d569f-b9e8-416d-b34c-11cf4adcd75b > [post_id] => 11e7ee > [created] => 2009-08-09 21:59:01 > ) > > [Post] => Array > ( > [title] => > [rank] => > [created] => > [description] => > [id] => > > ) > > ) > > [CODE] > foreach ($bookmarks as $key => $value) { > if (empty($value['Post']['id'])) { > unset($bookmarks[$key]['Post']); > }} > > [/CODE] > On Tue, Aug 11, 2009 at 11:19 AM, Dave Maharaj :: WidePixels.com < > > > > > > [email protected]> wrote: > > The thing is the Post info is there in the database > > > Scenario: > > The Post article has access level of 1 > > User that has an access level of 1 can see the Post and bookmark it. No > > problem > > > Later the owner of the Post changes the access level to 3....the user with > > level 1 access can no loger see that Post because his access level is too > > low, but his Bookmark for that Post still exists. But because the contain > > will pull all bookmarks that belongto the user andgetthe Posts where $access > > = 'Post.access' that info is no longer goingto get pulled, thats why it > > appears blank. > > > So I need to completely remove that bookmark from the array. > > > Trying something like: > > > foreach ($bookmark as $key => $value) { > > if (empty($value)) { > > unset($q[$key]); > > > but cant get it to work...still messing around with it > > > ------------------------------ > > *From:* joshua [mailto:[email protected]] > > *Sent:* August-11-09 12:41 AM > > *To:* [email protected] > > *Subject:* Re: Array help > > > 1. Use a callback function afterFind to loop the return array, remove the > > empty item. 2. How about give a condition when model->find. > > [CODE] > > 'conditions' => array(("*not*" => array ( "Post.id" => *null* )), //array > > of conditions > > [/CODE] > > On Tue, Aug 11, 2009 at 10:25 AM, Dave Maharaj :: WidePixels.com < > > [email protected]> wrote: > > >> I have a contain query which produces these results. > > >> Basically the user bookmarked a page when they had access. The Owner of > >> the > >> post has changed the level of who can view the Post so in this case this > >> user no longer can view the post hence the missing post data. It was not > >> grabbed because the conditions of the Post did not match the users access > >> level. > > >> But the bookmark still exists. Now in the query it pulls all bookmarks for > >> the user and the post related to the bookmark. How can I remove [1] from > >> the > >> array all together or all from the array if [Post] has no data? I can not > >> delete the bookmark when Posts change the access level because they may > >> change it back to a lower setting and allow those who did have it > >> bookmarked > >> to once again have access. I just need to remove the array entry(s) where > >> the Post array is empty. > > >> [0] => Array > >> ( > >> [Bookmark] => Array > >> ( > >> [id] => 38b7276f708 > >> [user_id] => 4a5d569f-b9e8-416d-b34c-11cf4adcd75b > >> [post_id] => 11e7ee > >> [created] => 2009-08-09 21:59:01 > >> ) > > >> [Post] => Array > >> ( > >> [title] => Test Title > >> [rank] => 2 > >> [created] => > >> [description] => Test dscription > >> [id] => 52louj > > >> ) > > >> ) > >> [1] => Array > >> ( > >> [Bookmark] => Array > >> ( > >> [id] => 38b7276f708 > >> [user_id] => 4a5d569f-b9e8-416d-b34c-11cf4adcd75b > >> [post_id] => 11e7ee > >> [created] => 2009-08-09 21:59:01 > >> ) > > >> [Post] => Array > >> ( > >> [title] => > >> [rank] => > >> [created] => > >> [description] => > >> [id] => > > >> ) > > >> ) > > >> Thanks, > > >> Dave > > > -- > > Thanks > > Joshua > > 5span.com <https://www.5span.com> > > -- > Thanks > Joshua > 5span.com <https://www.5span.com> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---
