indexes has_many :through


suppose have twin models, user city, assimilated third denote citypermission:



class citypermission < activerecord::base
belongs_to :city
belongs_to :user
end

class city < activerecord::base
has_many :city_permissions
has_many :users, :through => :city_permissions
end

class user < activerecord::base
has_many :city_permissions
has_many :cities, :through => :city_permissions
end


currently, i emanate join table, index table, controlling following emigration formula snippet:



create_table :city_permissions |t|
t.integer :user_id, :city_id
t.other_fields ...
end

add_index(:city_permissions, :user_id)
add_index(:city_permissions, :city_id)


are optimal indexes create? indexes grant discerning opening behind leading by join table, good discerning lookups within list itself, there improved way? reiterate bit differently, indexes, given city user instance variables category city user, grant city.users, city.city_permissions, user.cities, user.city_permissions perform equally well?



Comments

Popular posts from this blog

list macos calm editors formula editors

how hibernate @any-related annotations?

why does floated <input> control floated component slip over too distant right ie7, nonetheless firefox?