You need  a LEFT JOIN in your query. MenuPosting can't be in the WHERE
clause. Perhaps if you post the actual SQL query you're aiming for we
can figure out how to have Cake generate it.

What are post_start & post_end, anyway?

On Sat, Dec 6, 2008 at 10:06 PM, erturne <[EMAIL PROTECTED]> wrote:
>
> I've seen similar questions raised but haven't found a solution that
> works. Perhaps it's because I'm new to CakePHP and don't fully
> understand unbindModel(), bindModel(), container behaviors, etc.
> Anyway, I'll start simple and take suggestions.
>
> I have the following models in which a Menu hasAndBelongsToMany Entree
> and hasMany MenuPosting, and a MenuPosting belongsTo Menu:
>
> class Menu extends AppModel {
>        var $name = 'Menu';
>        var $hasAndBelongsToMany = 'Entree';
>        var $hasMany = array(
>                'MenuPosting' => array( 'dependent' => true )
>        );
>  }
>
> class MenuPosting extends AppModel {
>        var $name = 'MenuPosting';
>        var $belongsTo = 'Menu';
> }
>
> class Entree extends AppModel {
>        var $name = 'Entree';
>  }
>
> In my MenusController I have a display_current() action to find all
> menus that are currently posted:
>
> class MenusController extends AppController {
>        var $name = 'Menus';
>        function display_current() {
>
>                // Limit the query results to the menu that is visible (i.e. is
>                // currently posted)
>                $conditions = array(
>                        'MenuPosting.post_start <=' => date('Y-m-d H:i:s', 
> strtotime
> ("now")),
>                        'MenuPosting.post_end >' => date('Y-m-d H:i:s', 
> strtotime("now")),
>                );
>
>                // Find the menus that meets the conditions.
>                $this->set('menu', $this->Menu->find('all', array('conditions' 
> =>
> $conditions)));
>        }
>  }
>
> The error I get from this is:
> Warning (512): SQL Error: 1054: Unknown column
> 'MenuPosting.post_start' in 'where clause'
>
> $sql    =       "SELECT `Menu`.`id`, `Menu`.`old_id`, `Menu`.`created`,
> `Menu`.`modified`, `Menu`.`title` FROM `menus` AS `Menu`   WHERE
> `MenuPosting`.`post_start` <= '2008-12-06 22:02:57' AND
> `MenuPosting`.`post_end` > '2008-12-06 22:02:57'   "
>
> If I remove the conditions from the find I am able to retrieve all
> Menu and associated Entree, so I believe I have set up my database
> tables correctly.
>
> Any suggestions?
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to