Re: DRY for ActiveRecord w/PostgreSQL : defaults and validations

Kev Jackson
Mon, 19 Sep 2005 09:13:22 -0000

>
>
> In PostgreSQL practically full information about schema, intertable
> relationships and constraints can be extracted and injected to Rails app.


What about other RDBMSs that rails supports?

>
> Why to repeat yourself? If data constraints are already in schema,
> why not query DB to validate data before insert or update?
> Why not query DB for record defaults defined in schema?
> Why not retrieve associations defined by foreign keys from schema and
> inject them?

[snip ideas]

I agree with the DRY principle, but I''m thinking that if you do a query
to check the constraints for every insert, then you''ll be bogging the
database down with two calls for every insert instead of 1 call.  Just
something to consider.  Although the fact that the schema does define
the constraints should mean that the developer shouldn''t have to repeat
these in the model code.

Kev