On Thu, Jun 5, 2008 at 8:00 AM, winter <[EMAIL PROTECTED]> wrote:
>
> Everything was going fin untill I wanted to put some html select tags
> on the add view for the pivots table. The docs don't say how I can
> access data from another model - $this->set('units', $unit->Unit-
>>findAll());. Of course it's not $this. I read the docs some more and
> found out about ascociations. This is where hair begins to fall out.
>
> I've been making DB apps for quite some time now and never used
> something like this. It reminds me of MS Access. Ugh. Do I really need
> to set this up? Will it be flexible in the end? What ascociation do I
> use? I read about the hasAndBelongsToMany and the required join table.
> It sounds like it's just what I want to do. Is it? Can I just Item-
>>findAll() and pass the data to the view and put it in the html
> select?
>

Here's what I would try:

1) rename your 'pivots' table and change it to be named 'items_units'
and drop the ID field as you don't need it
2) create your HABTM relationship (instructions in the manual)

Then you can access info like this (these are only examples)

$results = $this->Item->find('all') ==> gives you all Items and their
associated units
$results = $this->Item->Unit->find('all', <conditions go here>) =>
gives you all units that match your conditions

Hope that helps (and I hope I did that right :) )

-- 
Chris Hartjes
Internet Loudmouth
Motto for 2008: "Moving from herding elephants to handling snakes..."
@TheKeyBoard: http://www.littlehart.net/atthekeyboard

--~--~---------~--~----~------------~-------~--~----~
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