I am using concerns for my rails application. I've different kind of users so I have made a loggable.rb
concern.
In my concern I have
included do
has_one :auth_info
end
because every of my user that will include the concern will have an association with auth_info table.
The problem is, what foreign keys I need to put in my auth_info table?
E.G
I've 3 kind of users:
- customer
- seller
- visitor
If I had only customer, in my table scheme I would have put the field
id_customer
but in my case?
You can solve this with polymorphic associations (and drop the concern):
Now you can retrieve:
You can use
rails g model AuthInfo loggable:references{polymorphic}
to create the model, or you can create the migration for the two columns by hand. See the documentation for more details.