Schema Draft - wxwang93/kikkr GitHub Wiki
users
| col | data_type | detail | 
|---|---|---|
| id | integer | not null, primary key | 
| username | string | not null, indexed, unique | 
| pw_digest | string | not null | 
| sess_tok | string | not null, indexed, unique | 
| first_n | string | not null | 
| last_n | string | not null | 
| created@ | datetime | not null | 
| updated@ | datetime | not null | 
- A User has many photos. A User has many albums. A User has many comments.
photos
| col | data_type | detail | 
|---|---|---|
| title | string | not null | 
| id | integer | not null, primary key | 
| user_id | integer | not null, indexed, f-key | 
| desc. | text | |
| created@ | datetime | not null | 
| updated@ | datetime | not null | 
- A photo belongs to a User. A photo has many comments. A photo has many tags.
albums
| col | data_type | detail | 
|---|---|---|
| id | integer | not null, primary key | 
| title | string | not null | 
| user_id | integer | not null, indexed, f-key | 
| descript | text | |
| created@ | datetime | not null | 
| updated@ | datetime | not null | 
- An Album belongs to a User. An Album has many Photos.
comments
| col | data_type | detail | 
|---|---|---|
| id | integer | not null, primary key | 
| user_id | integer | not null, indexed, f-key | 
| photo_id | integer | not null, indexed, f-key | 
| body | text | not null | 
| created@ | datetime | not null | 
| updated@ | datetime | not null | 
- A Comment belongs to a User. A Comment belongs to a Photo.
joins_photos_albums
| col | data_type | detail | 
|---|---|---|
| album_id | integer | not null, f-key | 
| photo_id | integer | not null, indexed, f-key | 
Associations Draft
class User
has_many :photos, class_name: :Photo, foreign_key: :user_id has_many :albums, class_name: :Album, foreign_key: :user_id has_many :comments, class_name: :User, foreign_key: :user_id end
class Photo
belongs_to :user, class_name: :User, foreign_key: :user_id belongs_to :album, class_name: :Album, foreign_key: :album_id has_many :comments, class_name: :Comment, foreign_key: :photo_id end
class Album
belongs_to :user, class_name: :User, foreign_key: :user_id has_many :photos, class_name: :Photo, foreign_key: :album_id end
class Comment
belongs_to :user, class_name: :User, foreign_key: :user_id belongs_to :photo, class_name: :Photo, foreign_key: :photo_id end