Hi guys,

I've just started working with CakePHP a month ago, and although I seem to
have a good grip over it, there are some things that just boggle my mind at
times. The latest:

I have a model for Publications that is associated to People (authors of the
publication) through a bridge table mapping them. I am mass importing
publications into the database. So, my logic is

<loop through the publications> {
<save the publication record>
if($commit) {    //save the publication record

                $publication = $publicationModel->read(NULL,
$publicationModel->getLastInsertId());

                /**
                 * Associating Authors/Editors
                 */
                $authorEditors = $import_data[$pubCtr]->arrAuthorsEditors;
                for ($iCtr=0; $iCtr<sizeof($authorEditors); $iCtr++) {

                    // Find the suthors if the already exist
                    echo "trying to find author ...";

                    $result = $publicationModel->Authoreditor->People->find(
                            "\"People\".\"lName\"='" .
$authorEditors[$iCtr]->lName . "' AND " .
                            "\"People\".\"mName\"='" .
$authorEditors[$iCtr]->mName . "' AND " .
                            "\"People\".\"fName\"='" .
$authorEditors[$iCtr]->fName . "'"
                    );

                    pr($result);

                    if (!empty($result["People"]["peopleId"])) {
                        // if they exist, just assoicate them in the bridge
table
                        $publication['Authoreditor'] = array(

'publicationId' => $publication['Publication']['publicationId'],

'peopleId' => $result['People']['peopleId'],
                                                                    'rank'
=> $iCtr+1,
                                                                    'type'
=> $authorEditors[$iCtr]->type
                                                                    );
                        $publicationModel->Authoreditor->create();
                        $commit = $commit &&
$publicationModel->Authoreditor->save($publication);
                        //echo "Saved "; pr($publication['Authoreditor']);
                    }
                    else {
                        // if not, create the records in the People table
                        $imp_authorsEditor = array('People' =>
                                                array (
                                                        'lName' =>
$authorEditors[$iCtr]->lName,
                                                        'mName' =>
$authorEditors[$iCtr]->mName,
                                                        'fName' =>
$authorEditors[$iCtr]->fName
                                                    )
                                                );

                        $publicationModel->Authoreditor->People->create();
                        $commit = $commit &&
$publicationModel->Authoreditor->People->save($imp_authorsEditor);
                        //echo "Saved "; pr($imp_authorsEditor);
                        if($commit) {
                            $publicationModel->Authoreditor->create();
                            $publication['Authoreditor'] = array(

'publicationId' => $publication['Publication']['publicationId'],

'peopleId' => $publicationModel->Authoreditor->People->getLastInsertId(),

'rank' => $iCtr+1,

'type' => $authorEditors[$iCtr]->type
                                                                        );
                            $commit = $commit &&
$publicationModel->Authoreditor->save($publication);
                            //echo "Saved ";
pr($publication['Authoreditor']);
                        }
                    }

                }

So the logic is simple .. for every publication, check if the author already
exists in the people table. If not, create a record and associate with the
publications. Now the problem that i noticed from the SQL logs:
If there are consecutive publications with the same author who is not in the
database, the find statement executes the first time and returns no record.
So a record is created for that author. But for the next record, though the
code exists, the select statement is not executed at all to look for the
author. Is there some kind of caching of SQL results so that if a find
method is called consecutively with the same parameters, the SQL is not
fired again and the old result is returned? This is wrong because in the
meanwhile the table was updated. Anyways, if this is the behavior, how do I
get around it?

Been stuck on this for a couple of days now ...

-- 
Nirav

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

Reply via email to