Martin wrote in post #1143301:
> Hi there,
>
> I have some major structure change issues with an ruby on rails
> application, and I'd like to ask you about how i can handle that. I
> will
> make some dummy problems for you to show what i want to reach:
>
> 1. Having a Client model with first_name and last_name should now come
> together as name:
> For the model it would be easy to have just
>
> def name
> first_name + ' ' + last_name
> end
>
> That works, but now I want to change the database this way, so we dont
> need
> the first_name and last_name anymore:
IMHO that is a bad idea. Chances are likely that you would come to
regret that decision. If you ever use either first_name or last_name
separately from each other then you violate First Normal Form (1NF). The
bigger issue is that once you decide to concatenate these two values in
to a single field there's no going back. There is no reliable algorithm
that can separate the two distinct values.
I say if you already have separate first and last names keep it that way
and add full_name method to the model. That costs you nothing really and
preserves flexibility in your app.
> I could create a migration having a name:string:index field.
> but after that - how can I make all the first_name and last_name applied
> there, and remove the first_name and last_name fields?
Whatever you decide, you are not limited to the ActiveRecord helpers in
your migrations. You can run any arbitrary SQL you want using the
execute method:
http://guides.rubyonrails.org/migrations.html#when-helpers-aren-t-enough
--
Posted via
http://www.ruby-forum.com/.