[Rails] Duplicating Constraints
Nicholas Van Weerdenburg
nick at activehitconsulting.com
Thu Dec 2 14:47:14 GMT 2004
One benefit of doing it this way is that OO-Relational mismatch is
better handled. It can be hard to map some OO design decisions
(inheritence and complex associations come to mind) to relational
constraints.
Also, more complex constraints can be expressed in terms of the domain
model and application logic, making it clearer to understand and
maintain. For complex constraints, you could start doing triggers and
stored procedures, but then you are creating complexity and
maintainability issues with significant application logic spread over
two languages and paradigms.
Some examples are deleting a record when the references to it reach 0,
or for certain types of users, a delete must go through an approval
process. Or constraints being conditional on values (e.g. "released" or
"published" documents).
Nick
David Heinemeier Hansson wrote:
>> Re-specifying constraints in ruby that are already specified in the
>> database is code duplication.
>
>
> Which is why my approach (and recommendation) is not to specify it in
> the database, but only in Ruby code. I understand that this is
> considered blasphemy among some database people, though.
>
> And this advice only applies to an Application Database design -- not
> Integration Databases. As do all of my opinions on the division
> between database and object-model.
> --
> David Heinemeier Hansson,
> http://www.basecamphq.com/ -- Web-based Project Management
> http://www.rubyonrails.org/ -- Web-application framework for Ruby
> http://macromates.com/ -- TextMate: Code and markup editor (OS X)
> http://www.loudthinking.com/ -- Broadcasting Brain
>
> _______________________________________________
> Rails mailing list
> Rails at lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
More information about the Rails
mailing list