I am working on a simple dictionary where I have words and synonyms to those words.
I am not sure which model is a better solution, working with a serialized attribute or association.
With association:
class ReservedWord < ActiveRecord::Base
has_many :synonyms
end
class Synonym < ActiveRecord::Base
belongs_to :reserved_word
end
With serialization:
class ReservedWord < ActiveRecord::Base
serialize :synonyms
end
In terms of data redundancy there isn’t such a big problem because synonyms aren’t supposed to repeat for other reserved words.
I appreciate your suggestions.
What is your sql query pattern expected to be like?
Using the
serializemechanism, you won’t be able to easily query based on synonyms. Based on being able to reverse lookupReservedWord‘s based on their synonyms, I would recommend thebelongs_to/has_manystandard rails approach.