Rails parent-child association
So I am creating a db schema that will represent a library of articles. Each article, however, can have many translations. So, There is a base article, which contains the shared info, and translations for that article. I currently have an article table/class and a translation table/class. Every article has_many translations and so on. My question though, is if there is a good way to delegate methods and find articles with this system开发者_如何转开发.
Should I make my own factory methods on the article class to retrieve the correct translation child? Should I add delegators on the translation so that I can reach back into the parent and get shared info about the article?
Another big concern is where named_scopes would go. Should they go on the article or its translation? I am trying to think of the best way to abstract away the difference between an article and its translation and just have a bunch of articles. Thoughts?
Thanks!
I think that i would use a scope to get an article and translation based on a language. It would be like that in the article model :
scope :translation, lambda { |language|
includes(:translation).
where("translations.language = ?", language )
}
精彩评论