开发者

Simple word - synonym model, serialized attribute or association?

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_m开发者_如何学编程any :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 serialize mechanism, you won't be able to easily query based on synonyms. Based on being able to reverse lookup ReservedWord's based on their synonyms, I would recommend the belongs_to/has_many standard rails approach.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜