Re: simple cakePHP question

2006-11-19 Thread [EMAIL PROTECTED]

> i've been looking at the API but I just don't see how I call
> _deleteHasMany? I do not want to cascade delete to child associations
> if I delete the master (in this case User). I want to delete ALL the
> rows on the many side of the relationship (in my case 'preferences')
> but the "one" side (the User) is not to be deleted.

_deleteHasMany method will not delete the User, just the child
(profile) records.
$this->User->_deleteHasMany($user_id, true);

However, if you have other "HasMany" associations, then they too will
also be deleted.

If that doesn't work for you... there's nothing wrong with doing it the
easy way:
$this->Preference->execute("DELETE FROM preferences WHERE user.id =" .
$user_id);


--~--~-~--~~~---~--~~
 You received this message because you are subscribed to the Google Groups 
"Cake PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: simple cakePHP question

2006-11-19 Thread jhughes96

> _deleteHasMany will loop through the preferences and delete each one.
> This would be the recommended way of deleting preferences since it
> would be done by the model.

HI,
i've been looking at the API but I just don't see how I call
_deleteHasMany? I do not want to cascade delete to child associations
if I delete the master (in this case User). I want to delete ALL the
rows on the many side of the relationship (in my case 'preferences')
but the "one" side (the User) is not to be deleted.

Hopefully this makes sense...thanks for your help so far and starting
to make a bit of progress...


Joel


--~--~-~--~~~---~--~~
 You received this message because you are subscribed to the Google Groups 
"Cake PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: simple cakePHP question

2006-11-19 Thread Matt

My bad, I just realised I misread the question and you don't want to
delete the User object.


--~--~-~--~~~---~--~~
 You received this message because you are subscribed to the Google Groups 
"Cake PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: simple cakePHP question

2006-11-19 Thread Matt

Hi Joel,

CakePHP makes this very easy for you. I'm assuming you've setup the
models so that User hasMany Preference and Preference belongsTo User.

To have it that CakePHP automatically deletes all the Preference
entries when you delete the parent User just set 'dependent' to true in
the hasMany array for User.

Cheers
Matt


--~--~-~--~~~---~--~~
 You received this message because you are subscribed to the Google Groups 
"Cake PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: simple cakePHP question

2006-11-19 Thread [EMAIL PROTECTED]

> What is the Cake way of deleting all the prefences for a User (but not
> the User itself) without having to loop over all the users prefences
> and call DELETE on the Preference model?

Look in the API at the model class. Specifically, checkout the del
method, and the _deleteHasMany method. There is a lot of stuff in the
API that you won't find anywhere else!

_deleteHasMany will loop through the preferences and delete each one.
This would be the recommended way of deleting preferences since it
would be done by the model.

Of course the other way would be:
$this->Preference->execute("DELETE FROM preferences WHERE user.id =
".$user_id);

But, if you have a "beforeDelete" method defined for the preference
model, the execute sql method would skip that logic.

sc


--~--~-~--~~~---~--~~
 You received this message because you are subscribed to the Google Groups 
"Cake PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



simple cakePHP question

2006-11-18 Thread jhughes96

Hi all,
I'm new to the Cake framework but not to PHP.

I apologise in advance for asking any dumbo questions if this is an
advanced group etc.

My simple question is this

I have a test Cake web app with two models - User and Preference - a
user has many preferences.

What is the Cake way of deleting all the prefences for a User (but not
the User itself) without having to loop over all the users prefences
and call DELETE on the Preference model?

...hopefully this makes some kind of sense!

Joel


--~--~-~--~~~---~--~~
 You received this message because you are subscribed to the Google Groups 
"Cake PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---