On 18 May 2010 16:58, chewmanfoo <[email protected]> wrote:
> Wow ok.
>
> So, the following:
>
> Class Shape < ActiveRecord::Base
>  attr_accessible :color_id
>  belongs_to :color
> end
>
> Class Color < ActiveRecord::Base
>  has_many :shapes
> end
>
> Now, in the console:
>
> sh = Shape.last
> ...
> sh.color_id
> 12
> sh.color.name
> "red"
> ...
> c = Color.find(12)
> c.name = "blue"
> c.save!
> ...
> sh.color.name
> "blue"

Why would you *ever* change a colour's name? If it's blue it's blue.
It's immutable; atomic.
It's a value in a *lookup* table.

If you want to store the "name" of the colour instead of its id
(because you find yourself often doing hideous things like changing
the values in lookups), then do so; you'll just have a poor,
inflexible DB.

-- 
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