The right way to do this would be to have 3 models each of which uses the
same table ( letter_contents )
with the correct conditions defined ( see finderQuery ) or place the
conditions within the Letter model's relationships.
[EMAIL PROTECTED] wrote:
>
>
> I considered option 2 as I believe this is a fairly straight forward
> model and it should be handled quite easily by cake. I have completed
> the "baking" as per your "recipe" and here is what I have come up
> with.
>
> When I bake the controller and the views, it gives me an error in the
> controller. Let me explain. Because the model describes the
> letter_content for all three sections (opening, middle, closing) by
> the array key, but references the same model for each section, the
> controller bakes the following with the generateList() function:
>
> $this->set('openings', $this->Letter->Opening->generateList());
> $this->set('middles', $this->Letter->Middle->generateList());
> $this->set('endings', $this->Letter->Ending->generateList());
>
> So now when I access the edit page, I get the following:
>
> Notice: Undefined property: Letter::$Opening
> Fatal error: Call to a member function generateList() on a non-object
>
> This is apparently due to the idea that $this->Letter->Opening is not
> really an object. Or is it?
>
> So, with some creative license and knowing that I needed LetterContent
> to fill in these areas, I update the controller to use the
> LetterContent model:
> var $uses = array('Letter', 'LetterContent');
>
> And then I update the generateList as follows: (notice the change in
> the reference to the LetterContent model and the addition of the
> conditions in the generateList function)
> $this->set('openings', $this->LetterContent-
>>generateList("`letter_section` = 'Opening'"));
> $this->set('middles', $this->LetterContent-
>>generateList("`letter_section` = 'Middle'"));
> $this->set('endings', $this->LetterContent-
>>generateList("`letter_section` = 'Ending'"));
>
> Now I can access the edit view and things are looking good except for
> one issue. Now all three drop downs (Opening, Middle, Ending) are
> populated with only openings. This is close to how things started, but
> instead of showing all letter_content in every drop down, I get all
> openings in every letter_content drop down.
>
> It seems like cake should handle this, and I know it is due to my
> inability to understand how it should be done. I don't want to have to
> strip out each table if it can be avoided. I am still sticking to my
> original thoughts that this is a simple model, very clear and concise,
> and is the best wat to maintain the tables to keep it easily
> understandable. It conforms to 3NF and is a valid schema.
>
> What am I missing? Any other ideas?
>
> >
>
>
--
View this message in context:
http://www.nabble.com/Multiple-N-to-Distinct-N-Model-tp14235103p14289751.html
Sent from the CakePHP mailing list archive at Nabble.com.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" 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
-~----------~----~----~----~------~----~------~--~---