My User model has $hasMany = array(
'Bookmark'
And my Post model has $hasMany = array(
'Bookmark'
I have a side module on the page where users view posts tht lists all the
users bookmarks for easy access and "save this post" link which saves the
post_id and the user_id to the bookmark table. I am just trying to write a
function that checks if it exists already then "You have bokmarked this post
already" or if not "Bookmark has been saved" type of idea.
Thanks,
Dave
-----Original Message-----
From: Joe Critchley [mailto:[email protected]]
Sent: April-11-09 3:06 PM
To: CakePHP
Subject: Re: Unique query
Hi Dave.
If your Post and User models both have a HABTM relationship to Bookmark,
then you can use the ** "unique" => true ** parameter in the association.
This means that if it does find a duplicate record, it will override it.
I hope this helps.
On Apr 11, 6:11 pm, "Dave Maharaj :: WidePixels.com"
<[email protected]> wrote:
> I am trying to query a table to determine if the record exists as I do
> not want duplicates but not sure if this is correct.
>
> $results = $this->find('first', array('conditions' =>
> array('Bookmark.user_id' => $user_id, 'Bookmark.post_id' =>
> $post_id))); debug($results);
>
> so if the user_id and the post_id are in the same row then do not save
> the bookmark because it already exists.
>
> Is this right?
>
> Dave
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---