|
|
 |
Re: FN-FORUM: What's the best development platform for creating Web 2.0 business applications?
date posted 22nd November 2007 10:34
Graham Stark wrote:
> On Wed, 2007-11-21 at 17:36 +0000, Dom Latter wrote:
>
>> On Wednesday 21 November 2007 16:57:10 Graham Stark wrote:
>>
>>
>>> A couple of Wikipedia articles show what I imagine Richard is trying to
>>> do:
>>>
>>>
>> Unless I'm missing something (quite possible) there's nothing wrong with
>> *adding* a unique auto-increment ID and timestamp to a record. It's
>> not going to break the "rules" and it may well help with debugging.
>>
>>
>
> I suppose it's a question of where you do things. If you have an
> auto-increment id field as the main (primary) key, you effectively have
> a logger: all incoming updates are accepted, and you sort out whether
> they're meaningful somewhere else, in application code or in some of the
> enormous SQL queries that get posted here from time time.
>
> The idea is, sort out what really makes a record unique (a username,
> perhaps, or a username and an order number) and use that. Let the
> database do the work for you.
>
It depends where you want to put the weight on your database- if you
want to work harder on insertion you might want an auto-increment ID
key, if you want it to work harder on select you may want to use
multiple field keys.
Given that for the type of databases I create for web stuff are likely
to be queried more than inserted to I tend to use auto-number ids for
primary keys. I can still sort out the referential integrity through
correctly created foreign keys and normalisation really has nothing to
do with it - a well normalised database will still often have regular id
fields.
I don't quite understand how leaving the logic in the database helps-
presumably if you try to insert bad data you get an error from the
database which you then have to handle in code? So why bother passing it
through code to the database in the first place, given that either
you're doing some processing on the way in?
It may be because I did a bunch of java stuff in my younger days but
I've always thought that the idea was to put your logic in the middle
tier rather than the database.
The view that Rails doesn't reflect a well normalised database model is
simply incorrect. It supports them fine, but it does expect auto-number
id fields, which is logical as most professional database designers
would use them anyway.
-ben
|
 |
|