[baseten-users] Fwd: Setting a relationship to nil
Réjean Lamy
rejean.lamy at mac.com
Tue May 5 20:21:52 EEST 2009
Hi !
... more details about my problem:
I can reproduce the pattern.
My test case:
- I have entered some departments (Dept-A, Dept-B and Dept-C)
- and employees (Empl-1, Empl-2, Empl-3)
- all employees are the Dept-A
Starting the Application everything is fine, I can select Dept-A, all
employees are listed ok, and I can select a manager, change it, all
ok, no error message in the console.
Selecting Dept-B or Dept-C displayed empty employees list with no
manager, so far so good.
Now, with Dept-A selected, when I set the manager relationship to nil
by pressing a button (see my code at the end of this email),
the manager popup showed "No value", perfect (using Navicat or
Postgres admin, I can see the manager relationship to NULL), its ok.
Next, always with Dept-A selected I change the manager popup from "No
Value" to an employee say "Empl-1", the change is done, but the
following error appear in the console:
2009-05-05 12:01:37.481 Departments[3240:10b] Cannot remove an
observer <NSKeyValueObservance 0x108f870> for the key path "firstName"
from <BXDatabaseObject 0x1090310> because it is not registered as an
observer.
... from there, always with Dept-A selected, if I changed the manager
from "Empl-1" to say "Empl-2" , now the following error showed in the
console:
2009-05-05 12:11:16.654 Departments[3240:10b] Cannot remove an
observer <BXSynchronizedArrayController 0x1077250> for the key path
"manager.firstName" from <Department 0x109e3c0>, most likely because
the value for the key "manager" has changed without an appropriate KVO
notification being sent. Check the KVO-compliance of the Department
class.
... from this point, things goes very bad, if I switch from "Dept-A"
to "Dept-B", I see the "Dept-B" employees table populated with the
Dept-A employees !
(there is no employees in Dept-B) !
Is the tables changed ? No, I start Postgres Admin or Navicat and see
all employees are well in "Dept-A". Dept-B show no employees.
... now fun things, switching between Dept-A then Dept-B selection,
one time Dept-B showed no employees the second time Dept-B showed all
the Dept-A employees. Switching again and again displayed exactly the
same pattern. Once on two Dept-B listed the Dept-A employees.
From the error messages showed in the console, something seems going
out of sync in BXSynchronizedArrayController.
Again, if I don't set the manager relationship to nil, no problem at
all.
But the time the manager is set to nil... boom !! (no crash but
inconsistencies )
Following is the code used I wrote to set a manager to nil on button
click:
---------------------------------
// DepartmentViewController.h
#import "ManagingViewController.h"
@interface DepartmentViewController : ManagingViewController {
IBOutlet NSArrayController *deptAC;
IBOutlet NSTextField *textfield;
}
- (IBAction) setManagerToNil: (id) sender;
@end
---------------------------------
// DepartmentViewController.m
#import "DepartmentViewController.h"
#import "Department.h"
static NSString *selectedEmployeeContext = @"selectedEmployeeContext";
@implementation DepartmentViewController
// init method is Hillegass unchanged code
- (id)init
{
if (![super initWithNibName:@"DepartmentView"
bundle:nil])
return nil;
[self setTitle:@"Departments"];
return self;
}
// I added a Button "Set Manager to nil" in the Department view
- (IBAction) setManagerToNil: (id) sender
{
NSBeep();
NSUInteger index = [deptAC selectionIndex]; // the selected
department index
Department *department = [[deptAC arrangedObjects]
objectAtIndex:index]; // the selected department object
[department setManager:nil]; // !!! Things will goes bad
if manager relationship is set to nil :(
// [department setValue:nil forKey:@"manager"]; // alternate
way I tried, but with same results
// [department setPrimitiveValue:nil forKey:@"manager"]; // same
results too ...
}
@end
---------------------------------
//Department.h
#import <BaseTen/BaseTen.h>
@class Employee;
@interface Department : BXDatabaseObject { }
@property (retain) NSString * deptName;
@property (retain) Employee * manager;
@property (retain) NSMutableSet* employees;
@end
---------------------------------
//Department.m
#import "Department.h"
@implementation Department
@dynamic deptName;
@dynamic manager;
@dynamic employees;
@end
---------------------------------
Any ideas ?
Rejean lamy
PS: I used BaseTen 1.6.2 and also experimented with compiling
frameworks from svn trunk, but same results.
PS2: Good work BX staff on trunk, I appreciated now to be able to use
the same Xcode model name for the to-many relationship (i.e.
"employees")
Début du message réexpédié :
> De : Tuukka Norri <tuukka.norri at karppinen.fi>
> Date : 5 mai 2009 10:50:19 HAE
> À : BaseTen-Users <baseten-users at lists.basetenframework.org>
> Objet : Rép : [baseten-users] Setting a relationship to nil
> Répondre à : BaseTen-Users <baseten-users at lists.basetenframework.org>
>
> Réjean Lamy kirjoitti 5.5.2009 kello 15.02:
>> I would like to know if this is legal to set a relationship to
>> "nil" like this:
>>
>> [department setManager:nil];
>
> Hi!
> This should be perfectly alright. If you have some new sample code,
> please send it if you can, and we'll see if there's a bug.
> --
> Best regards,
> Tuukka Norri
> MK&C
>
> _______________________________________________
> baseten-users mailing list
> baseten-users at lists.basetenframework.org
> http://lists.basetenframework.org/mailman/listinfo/baseten-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.basetenframework.org/pipermail/baseten-users/attachments/20090505/c737ca98/attachment.htm>
More information about the baseten-users
mailing list