nkallen / cache-money

A Write-Through Cacheing Library for ActiveRecord
Apache License 2.0
994 stars 107 forks source link

howto: indexing habtm models? #3

Open dkindlund opened 15 years ago

dkindlund commented 15 years ago

Can you provide an example on how to properly index fields in the (automagically generated) "join" table that rails creates when 2 models are declared as habtm?

For example: class Role < ActiveRecord::Base

has_and_belongs_to_many :users

end

class User < ActiveRecord::Base

has_and_belongs_to_many :roles

end

Then, how do I properly index the "role_id" and "user_id" columns in the automatically generated "roles_users" table?

It seems that cache-money requires index declarations in all models, but the problem is, there's no actual model file declared for the "roles_users" table. So, do I need to manually create the model file...? Or is there some other way to accomplish what I want?

Thanks.

nkallen commented 15 years ago

I don't think there's a way to accomplish this right now :( . Try digging through the HABTM code and see if you can write a patch?