The 'problem' seems to be with generateList() which is used by
scaffolding to provide data for the 'select' construct. It ignores the
condition you set for Letter model.
You may consider 2 options:
1) if you want to take advantage of scaffolding then you might need to
break the table 'letter_contents' into 3.
2) If you prefer the existing table design, you might need to run bake
again to re-create the controller (select option that creates 'add',
edit, view, delete functions). Then in the 'edit' functions, provide
condition parameter for generateList().
Zonium
On Dec 8, 6:46 pm, Santa <[EMAIL PROTECTED]> wrote:
> I have a model situation that I cannot find in the group anywhere. I
> have spent nearly a day searching. I am hoping there is a model guru
> that can help.
>
> First, to help you understand, I am putting together a pre-canned form
> letter tool. I will have three sections to the letter using all pre-
> written content; the opening, the middle, and the end. Each letter
> will have 1 of each prewritten section, everytime, all the time, no
> acceptions. So when I create a letter, I choose from the different
> sections of pre-written letter content to create my letter. Here is
> how I modeled it.
>
> CREATE TABLE `letter_contents` (
> `id` int(11) NOT NULL auto_increment,
> `letter_section` enum('Opening','Middle','Ending') NOT NULL,
> `letter_content` text NOT NULL,
> PRIMARY KEY (`id`)
> );
>
> CREATE TABLE `letters` (
> `id` int(11) NOT NULL auto_increment,
> `openingid` int(11) NOT NULL default '0',
> `middleid` int(11) NOT NULL default '0',
> `endingid` int(11) NOT NULL default '0',
> PRIMARY KEY (`id`)
> );
>
> Now when I set the controllers to use scaffolding and write the models
> so that only openings show for the openingid and only midddle shows
> for the middleid, etc., it doesn't return the expected result. In the
> drop down for openings, I show ALL the letter_content. Here are my
> models.
>
> LETTER MODEL
> class Letter extends AppModel {
> var $name = 'Letter';
> var $belongsTo = array(
> 'Openings' =>
> array('className' => 'LetterContent',
> 'conditions' =>
> "letter_contents.letter_section = 'Opening'",
> 'order' => '',
> 'foreignKey' => 'openingid'
> ),
> 'Middle' =>
> array('className' => 'LetterContent',
> 'conditions' =>
> "letter_contents.letter_section = 'Middle'",
> 'order' => '',
> 'foreignKey' => 'middleid'
> ),
> 'Ending' =>
> array('className' => 'LetterContent',
> 'conditions' =>
> "letter_contents.letter_section = 'Ending'",
> 'order' => '',
> 'foreignKey' => 'endingid'
> ),
> );
>
> }
>
> I have also tried to put a $hasMany in the LetterContent model as
> follows:
>
> var $hasMany = array(
> 'LetterOpening' =>
> array('className' => 'Letter',
> 'conditions' => 'Letter.openingid = id',
> 'order' => '',
> 'foreignKey' => 'id'
> ),
> 'LetterDeeds' =>
> array('className' => 'Letter',
> 'conditions' => 'Letter.deedsid = id',
> 'order' => '',
> 'foreignKey' => 'id'
> ),
> );
>
> What I do not want to do if it can be avoided, is strip the content
> out into three separate tables. From my perspective, there is no need
> to do that. This is 3NF from my perspective. If I were writting the
> content each time from scratch, I would store the letter data right
> inside the table. So this is no different from that.
>
> Anyone have any idea how to get this model to work so that all my "pre-
> written" content can reside in one table and use the letter_section to
> know what content to show in the various sections in the Letter model?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---