English 中文(简体)
核心数据简单一对一的关系
原标题:Core data simple one-to-one relationship
  • 时间:2011-10-21 20:34:59
  •  标签:
  • core-data

我有一个简单的核心数据问题。

I set up an employee entity and an employeeDetails entity. Both have a relationship pointing to the other to form a simple one-to-one relationship. Each employee has one employeeDetail.

我能够储存新雇员,必要时挑选新雇员。 我的问题是,我如何同时储存配对员工,我如何找回手套中对应雇员的细节?

Thanks for any help you can provide.

问题回答

在雇员的夫妻中,使用每个插入的触发器。

http://en.wikipedia.org/wiki/Database_trigger

我通过为各实体重新创建这一类别,解决了我的问题,核心数据将增加反映关系的动态变量。 当我储存这些实体时,我创建了一名雇员和雇员。

- (void)addEmployee :(NSDictionary *)_employee {    

    // Create a new instance of the Employee entity.
    Employee *employee = (Employee *)[NSEntityDescription insertNewObjectForEntityForName:@"Employee" inManagedObjectContext:managedObjectContext];
    EmployeeDetails *employeeDetails = (EmployeeDetails *)[NSEntityDescription insertNewObjectForEntityForName:@"EmployeeDetails" inManagedObjectContext:managedObjectContext];

    // Add the new employee
    employee.firstName = [_employee objectForKey:@"first_name"];;
    employee.lastName = [_employee objectForKey:@"last_name"];;
/* --> */   employee.details = employeeDetails;  // Associate with details object

    // Add details
    employeeDetails.address    = [self getValue:[e objectForKey:@"street_address"]];   
    employeeDetails.cellPh     = [self getValue:[e objectForKey:@"cell"]];

    // Save the data
    NSError *error;
    if (![managedObjectContext save:&error]) {
        NSLog(@"core date save error: %@", error);
    }   
}




相关问题
iPhone Core Data Recursive Relationships

I m having some trouble with a recursive relationship in core data. I ve got a managed object called a "SearchCategory", and that category can have "Categories" and it can also have a "Category." In ...

Plist Hierarchy and All Option

I have a string of data in a plist, which I ve got to display, hierarchically like this: Menu>Chapter>SubChapter>item>item details This might be super simple, in my initial menu, how would I have ...

Fetched Properties v Relationships (Core Data - iPhone)

I m a new iPhone developer (of about 4 months or so) who is starting to look at Core Data. In the "Beginning iPhone 3 Development" book by Dave Mark it mentions that the main difference between ...

Cocoa Core Data newbie how-tos

I am one of the great unwashed masses of .NET developers keen to try their hands at Mac OS X development. At the moment I am trying to figure out the various elements of Cocoa and getting a bit stuck ...

中间储存的核心数据

我想将核心数据作为输入数据库服务器更大数据集的切身。

Limit the returned resultset in CoreData

In CoreData, if I want to limit the returned resultset to 100, is it enough to just set the fetch limit to 100, or do I need to set the fetch batch size to 100 as well?

热门标签