On 8 January 2011 10:13, Mauro <[email protected]> wrote:
> On 8 January 2011 09:19, Colin Law <[email protected]> wrote:
>
>> Is there an expiry_date column in the database?
>
> Yes there is.
>
>> in the controller if that column exists.  However, if the expiry date
>> is *always* +90 days then you should not put it in the database, but
>> should provide an instance method in the model, something like
>>
>> def expiry_date
>>  self.issue_date + 90.days
>> end
>>
>> Then you can say durc.expiry_date and will always get issue date + 90
>> days.  The method may have to be a little more complex if issue_date
>> can ever be nil.
>
> I have not thought about this, I have put curc_expiry_date in the
> database, is it wrong?

If expiry date can always be calculated from issue date then it is
wrong to put expiry date in the database.  It increases the database
size and access time but also adds complexity to the code.  For
example you have to remember to update it whenever the issue date is
changed.  If you use a method to access it the code is simpler.  Note
that other code accessing curc.expiry_date will not see any difference
between a value stored in the database and the access method I have
suggested.  This is known as a virtual attribute.  You might like to
google for database normalization if you want to find more about how
to design the database.

Colin

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to