You would probably be better off checking if the entry already exists BEFORE creating a duplicate, then deleting it ?

That way you could have a 'Follow' if the entry does not exist and an 'Unfollow' if it does exist.

Assuming this is a HABTM relationship, you would just need to query the following model then look in the follower relationship to see if the users ID exists.

Steve (Ratty)


On 14/06/12 13:40, JonStark wrote:
I have a table with the following fields :

id follower_id following_id

So when a user clicks "follow" on an other user's profile, an entry like this is created :

15 1 3

meaning user with id 1 follows user with id 3.

If user 3 follows 1, then an entry like

16 3 1

is created.

But, in order to prevent users for following many time a same user, leading to entry such as :

17 3 1
18 3 1
19 3 1

and so on, I want to replace "follow" by "unfollow" if the entry is already saved.

So my question is : how can i "scan" the table to check if an entry as both X as follower_id AND Y as following_id ?

Thanks a lot.
--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at http://groups.google.com/group/cake-php

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to