Yup, that was it! I'd got totally muddled up.
I have now switched that PK definition to the correct one, and changed
the releationship in the model to 'belongsTo' and everything is hunky
dory!
It was definately one of those 'I've been staring at this for far too
long and can't see the problem...'
Cheers!
d.
On Nov 21, 6:06 pm, mehodgson <[EMAIL PROTECTED]> wrote:
> This may be the problem, in your controller your set:
>
> $this->params['marked_jobs']['Mark']['jm_j_id'] = $j_id;
>
> and in your model your set:
>
> var $primaryKey = 'jm_j_id';
>
> ...so in your controller you are setting the passed value to 'jm_j_id'
> which is the PK.
>
> On Nov 21, 8:34 am, designvoid <[EMAIL PROTECTED]> wrote:
>
> > Hi there!
>
> > I'm trying to perform an insert query via an ajax call, having
> > searched throughout the group, I have come to the conclusion that it
> > is something to do with Cake taking the only parameter passed as the
> > PK and performing an update rather than an insert. I have found posts
> > regarding this suggesting setting the id to null at start of function,
> > using the model->create command etc, but none of these seem to work...
>
> > I'll paste some snippets, this is my view file with the AJAX call:
>
> > <input id="job_mark_<?php echo $item['j_id']; ?>" type="checkbox"
> > onClick="new Ajax.Updater('jobs_marked','markit/<?php echo
> > $item['j_id']; ?>', {asynchronous:true, evalScripts:true});" />
>
> > This is my controller function:
>
> > function markit($j_id)
> > {
> > $this->Mark->id = null;
> > $this->params['marked_jobs']['Mark']['jm_j_id'] = $j_id;
>
> > if ($this->Mark->save($this->params['marked_jobs']))
> > {
> > $this->set('jobs', $this->Job->findAll());
> > $this->set('marked_jobs', $this->Mark->findAll());
> > $this->render('marked', 'ajax');
> > }
> > }
>
> > And this is my 'mark' model:
>
> > class Mark extends AppModel {
> > var $name = 'Mark';
> > var $primaryKey = 'jm_j_id';
> > var $useTable = 'jobs_marked';
>
> > var $hasOne = array('Job' =>
> > array('className' => 'Job',
> > 'conditions' => '',
> > 'order' => '',
> > 'dependent' => true,
> > 'foreignKey' => 'j_id'
> > )
> > );
>
> > }
>
> > I hope that this is something simple that I have overlooked and one of
> > you fine people can shed some light on it...
> > TIA,
> > d.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---