No-one has an answer? I'd say a lot of people use the same construction so it won't be that hard ... I just don't know how.
On Aug 6, 3:01 am, Ruud Gâst <[EMAIL PROTECTED]> wrote: > Hello there, > > I've got a simple construction of two models: users and familymembers; > every user belongs to a familymember and a familymember has one user. > So the database looks like this: > > `familymembers` ( > `id` int(11) auto_increment, > `firstname` varchar(20), > `lastname` varchar(100), > `gender` tinyint(4), > `dob` date, > `email` varchar(100), > `created` datetime, > `deleted` tinyint(1) > ); > `users` ( > `id` int(11) auto_increment, > `familymember_id` int(11), > `username` varchar(20), > `password` varchar(255), > `deleted` tinyint(1), > `created` datetime > ); > > I'm using a hasOne association in the Familymember model, so it will > only return one record ... great! But now I want to be able to keep > old records, so if a user would be removed Users.deleted will be set > to 1. Also great, so I thought, just fix the association so it will > only return records where Users.deleted = 0. So I did that like this: > > var $hasOne = array( > 'User' => > array( > 'className' => 'User', > 'conditions' => 'User.deleted = 0' > ) > ); > > The CakePHP Manual says the following about hasOne associations: > > "We could use this to tell Cake to only associate a Profile that has a > green header, if we wished. To define conditions like this, you'd > specify a SQL conditions fragment as the value for this key: > "Profile.header_color = 'green'"." -http://manual.cakephp.org/ > chapter/models > > So in my case this model should only associate a Familymember that has > not been deleted. But this simply doesn't work, Cake ignores the > 'conditions'-part alltogether. I even tried to make conditions that > would generate errors ... didn't get an error and none of the > 'conditions' are included in the SQL-query. > > I've googled around to see if anyone else has a similar problem or > similar system explained but haven't had any luck so far. So is there > anyone who can tell me what I'm doing wrong, or even better, tell me > how to do this the right way. > > Thanks! > > By the way: I'm using PHP 4.4 and CakePHP 1.1.14.4797 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---