Hi everybody
I am totally new to rails and I am trying to start a
tiny project to get familiar with rails. But I already
got my first problem and I would be happy if somebody
could point me in the best and cleanest direction.
I am trying to develop a small gallery app. Since I
would like to add more features in future I am trying
to design a clean OO architecture of my models:
The base object should be NODE. All other objects
extend NODE, those are GALLERY and IMAGE (a GALLERY
consists of 0…* IMAGEs). Each NODE has an owner
(user_id) plus some default fields like created_on and
updated_on. Futhermore there is an object COMMENT
which can be attached to any object that extends NODE
(belongs_to NODE).
According to this design I modeled the db schema as
follows:
CREATE TABLE nodes
(
id
int(11) NOT NULL auto_increment,
user_id
int(11) NOT NULL default ‘0’,
created_on
timestamp NOT NULL default
CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
updated_on
timestamp NOT NULL default ‘0000-00-00
00:00:00’, PRIMARY KEY (id
)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
DROP TABLE IF EXISTS galleries
;
CREATE TABLE galleries
(
id
int(11) NOT NULL auto_increment,
node_id
int(11) NOT NULL default ‘0’,
user_id
int(11) NOT NULL default ‘0’,
title
varchar(255) NOT NULL default ‘’,
descr
text NOT NULL,
PRIMARY KEY (id
),
KEY user_key
(user_id
),
KEY node_key
(node_id
)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
DROP TABLE IF EXISTS images
;
CREATE TABLE images
(
id
int(11) NOT NULL auto_increment,
user_id
int(11) NOT NULL default ‘0’,
gallery_id
int(11) NOT NULL default ‘0’,
node_id
int(11) NOT NULL default ‘0’,
title
varchar(255) NOT NULL default ‘’,
descr
text NOT NULL,
PRIMARY KEY (id
),
KEY gallery_key
(gallery_id
),
KEY node_key
(node_id
),
KEY user_key
(user_id
)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
CREATE TABLE comments
(
id
int(11) NOT NULL default ‘0’,
node_id
int(11) NOT NULL default ‘0’,
user_id
int(11) NOT NULL default ‘0’,
title
varchar(255) NOT NULL default ‘’,
body
text NOT NULL,
created_on
timestamp NOT NULL default
CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
updated_on
timestamp NOT NULL default ‘0000-00-00
00:00:00’,
PRIMARY KEY (id
),
KEY user_key
(user_id
),
KEY node_key
(node_id
)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
CREATE TABLE users
(
id
int(11) NOT NULL auto_increment,
created_on
timestamp NOT NULL default
CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
`updated_on` timestamp NOT NULL default
‘0000-00-00 00:00:00’,
nickname
varchar(255) NOT NULL default ‘’,
firstname
varchar(255) NOT NULL default ‘’,
lastname
varchar(255) NOT NULL default ‘’,
email
varchar(255) NOT NULL default ‘’,
passwd
varchar(100) NOT NULL default ‘’,
PRIMARY KEY (id
)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
My question now is, is this a nice design and is this
easy to implement with rails? And how should I
implement my models in rails, should I use inheritance
or make sure that each NODE extensions sets the
correct data in the NODE table?
Regards, Luca
Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de