If "A deal has many tickets, and belongs to one item.", then why you bind:

$this->Ticket->bindModel(array('belongsTo' => array('Deal'
=>array('foreignKey' => 'deal_id'))));
$this->Ticket->bindModel(array('belongsTo' => array('Item'
=>array('foreignKey' => 'deal_id'))));

Ticket belongsTo Deal, Ticket belongsTo Item ?

On Jan 19, 2008 6:43 PM, phpjoy <[EMAIL PROTECTED]> wrote:
>
> No, there isn't such a key Ticket.item_id
> Warning (512): SQL Error: 1054: Unknown column 'Ticket.item_id' in 'on
> clause' [CORE\cake\libs\model\datasources\dbo_source.php, line 440]
>
> There's Deal.item_id
> Basically a ticket belongs to a deal. A deal has many tickets, and
> belongs to one item.
>
> It should be:
> Ticket->Deal->Item
>
> I need to get Item.title for every ticket that I have.
> So my custom SQL query is correct, but I wonder how I could use binds
> to do that.
>
> That's the custom query I came up with:
> SELECT `Ticket`.`id`, `Deal`.`file`, `Item`.`title` FROM `tickets` AS
> `Ticket` LEFT JOIN `deals` AS `Deal` ON (`Ticket`.`deal_id` =
> `Deal`.`id`) LEFT JOIN `items` AS `Item` ON (`Deal`.`item_id` =
> `Item`.`id`) WHERE `Ticket`.`user_id` = 1
> When I left join 'items' to deal.item_id, it works.
>
> On Jan 19, 6:40 pm, "Dardo Sordi Bogado" <[EMAIL PROTECTED]> wrote:
> > You are putting:
> >
> > $this->Ticket->bindModel(array('belongsTo' => array('Item' =>
> > array('foreignKey' => 'deal_id'))));
> >
> > instead of :
> >
> > $this->Ticket->bindModel(array('belongsTo' => array('Item' =>
> > array('foreignKey' => 'item_id'))));
> >
> > it's a copy and paste error.
> >
> > HTH,
> > - Dardo Sordi.
> >
>
> > On Jan 18, 2008 9:39 PM, phpjoy <[EMAIL PROTECTED]> wrote:
> >
> >
> >
> > > I wonder how I could make a simple query to work through bind(), and
> > > not use a custom query.
> >
> > > I'm binding two models for a model:
> > > $this->Ticket->bindModel(array('belongsTo' => array('Deal' =>
> > > array('foreignKey' => 'deal_id'))));
> > > $this->Ticket->bindModel(array('belongsTo' => array('Item' =>
> > > array('foreignKey' => 'deal_id'))));
> >
> > > The resulting query I get is this:
> > > SELECT `Ticket`.`id`, `Deal`.`file`, `Item`.`title` FROM `tickets` AS
> > > `Ticket` LEFT JOIN `deals` AS `Deal` ON (`Ticket`.`deal_id` =
> > > `Deal`.`id`) LEFT JOIN `items` AS `Item` ON (`Ticket`.`deal_id` =
> > > `Item`.`id`) WHERE `Ticket`.`user_id` = 1
> >
> > > Now, instead of:
> > > `Item` ON (`Ticket`.`deal_id` = `Item`.`id`)
> > > I need:
> > > `Item` ON (`Deal`.`item_id` = `Item`.`id`)
> >
> > > Which gives this query:
> > > SELECT `Ticket`.`id`, `Deal`.`file`, `Item`.`title` FROM `tickets` AS
> > > `Ticket` LEFT JOIN `deals` AS `Deal` ON (`Ticket`.`deal_id` =
> > > `Deal`.`id`) LEFT JOIN `items` AS `Item` ON (`Deal`.`item_id` =
> > > `Item`.`id`) WHERE `Ticket`.`user_id` = 1
> >
> > > I tried binding item to deal, and CakePHP made 200 queries instead.
> > > That didn't work too well.
> > > Any ideas how I could make a slim query with CakePHP, without using
> > > query()?
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" 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