Suppose I have 3 models musician, developer and doctor, each one has some attributes in common, for example name, lastname, birthday and email, but they have some attributes specific for example musician(instrument, band), developer (language, SO) and doctor (licence, clinic).
My approach is something like this:
class Person < ActiveRecord::Base
belongs_to :general, :polymorphic => true
end
class Musician < ActiveRecord::Base
has_one :person, :as => general
end
class Developer < ActiveRecord::Base
has_one :person, :as => general
end
class Doctor < ActiveRecord::Base
has_one :person, :as => general
end
The question is, this kind of model relationships affects performance because of the polymorphic association?, or are there a better solution to consider?
Yes, polymorphic association does affect performance. Sometimes positively, sometimes negatively, all dependent on how your application is used.
As far as the case you presented in concerned, I would not used polymorphic association. I would just have 3 models, with common attributes like name, lastname, birthday and email all in three models. This is more advantageous because if you wanted to find out the name of a musician, you only need to make 1 database call in Musician table. In polymorphic association case, you need 2 database calls in Musician table and Person table.