### 24.2 Creating with DBModeler ¶

To recreate the example model with DBModeler,

select Document, New from the main menu then property Add entity twice. set the name and external names to ’authors’ and ’books’

select Document, Set Adaptor Info, and select SQLite, and click Ok, this will bring up the SQLite login panel, where you need to provide it a path for where to create the model file.

Each Adaptor will have different requirements, so each login panel is quite different. Other adaptors may have a server address, username, and database names.

select the authors entity in the outline view, after expanding the model add an attribute to authors by selecting Property, Add attribute set the name and column name to ’authorID’, and select the switch button with a key icon, to set it as the primary key for the entity. Set the value class name to NSNumber and the external type to INTEGER

Add another entity, set the name and column names to ’name’. Select the switch button which looks like a jewel icon to set it as a Class Property. Set the Value Class Name to NSString and external type to TEXT.

now do the same with books, name them bookID, authorID, and title. make sure bookID is set as the primary key not authorID in the books entity. And that title is set as a class property.

title is a NSString/TEXT, where authorID and bookID are NSNumber/INTEGER

now add a relationship to authors name it toBooks, and Tools, inspector in the destination table, select To many, and books as the destination entity.

select authorID as the source and destination attributes

add a relationship to books, name it toAuthor. Select author as the destination entity, and authorID as the source and destination attributes.

The select Document, Save, from the main menu.