Creating the database and tables
We will use three tables: User, Blog and Post. We also use a database called test. You can create the tables using the schema below or you can let ActiveRecord generate the schema for you.

As you can see the User table has no relation with the others. It is going to be used only for controlling access to the application. Meanwhile the Blog and Post are related. A blog can have many posts, hence the relation is blog is one-to-many and on the post is many-to-one.
CREATE TABLE Blog ( [Id] [int] IDENTITY (1, 1) NOT NULL, [Name] [varchar] (25) NOT NULL, [Author] [varchar] (25) NOT NULL ) ON [PRIMARY] CREATE TABLE Post ( [Id] [int] IDENTITY (1, 1) NOT NULL, [BlogId] [int] NOT NULL, [Title] [varchar] (100) NOT NULL, [Contents] [text] NOT NULL, [Category] [varchar] (25) NULL, [Created] [datetime] NOT NULL, [Published] [bit] NOT NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] CREATE TABLE User ( [Id] [int] IDENTITY (1, 1) NOT NULL, [UserName] [varchar] (25) NOT NULL, [Password] [varchar] (15) NOT NULL ) ON [PRIMARY] ALTER TABLE Blog WITH NOCHECK ADD CONSTRAINT [PK_Blog] PRIMARY KEY CLUSTERED ( [Id] ) ON [PRIMARY] ALTER TABLE Post WITH NOCHECK ADD CONSTRAINT [PK_Post] PRIMARY KEY CLUSTERED ( [Id] ) ON [PRIMARY] ALTER TABLE User WITH NOCHECK ADD CONSTRAINT [PK_User] PRIMARY KEY CLUSTERED ( [Id] ) ON [PRIMARY]
Proceed with Creating the classes.