I created an index with person_id and club_id but I can''t figure out
how to properly access it (doesn''t show up in the find_by... lists)
Can someone provide me a sample find statement to best use this index
Thanks.
class CreateMembers < ActiveRecord::Migration
def self.up
create_table :members do |t|
t.integer :club_id
t.integer :person_id
t.text :comment
t.string :status
t.string :member_type
t.integer :registrations_count
t.timestamps
end
add_index :members, :club_id
add_index :members, :person_id
add_index :members, [:person_id, :club_id]
end
def self.down
drop_table :members
end
end
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2010-Mar-29 20:37 UTC
Re: How to use find method on table with two column index
On Mar 29, 7:51 pm, RVRoadie <rvroa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I created an index with person_id and club_id but I can''t figure out > how to properly access it (doesn''t show up in the find_by... lists) > > Can someone provide me a sample find statement to best use this indexYou don''t need to do anything explicitly - just find :all, :conditions => ... will use the index if needed (you may have been looking for find_by_xxx_and_yyy though) The index on person_id is usually superfluous - when you have a multicolumn index then any left prefix of that index is also an index ie the index on [:person_id, :club_id] can be used as an index on just person_id Fred> > Thanks. > > class CreateMembers < ActiveRecord::Migration > def self.up > create_table :members do |t| > t.integer :club_id > t.integer :person_id > t.text :comment > t.string :status > t.string :member_type > t.integer :registrations_count > > t.timestamps > end > > add_index :members, :club_id > add_index :members, :person_id > add_index :members, [:person_id, :club_id] > end > > def self.down > drop_table :members > end > end-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Miquel Oliete
2010-Apr-04 11:09 UTC
Re: How to use find method on table with two column index
Hi there
What you are trying to find is (I think it''s the easiest option )
class CreateListSongs < ActiveRecord::Migration
def self.up
create_table :members, :primary_key =>[:club_id, :person_id] do |t|
t.integer :club_id
t.integer :person_id
t.text :comment
t.string :status
t.string :member_type
t.integer :registrations_count
t.timestamps
end
end
def self.down
drop_table :members
end
end
Hope this helps
Best regards
Miquel
On Mon, 29 Mar 2010 11:51:48 -0700 (PDT)
RVRoadie wrote:
> I created an index with person_id and club_id but I can''t figure
out
> how to properly access it (doesn''t show up in the find_by...
lists)
>
> Can someone provide me a sample find statement to best use this index
>
> Thanks.
>
> class CreateMembers < ActiveRecord::Migration
> def self.up
> create_table :members do |t|
> t.integer :club_id
> t.integer :person_id
> t.text :comment
> t.string :status
> t.string :member_type
> t.integer :registrations_count
>
> t.timestamps
> end
>
> add_index :members, :club_id
> add_index :members, :person_id
> add_index :members, [:person_id, :club_id]
> end
>
> def self.down
> drop_table :members
> end
> end
>
> --
> You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
> To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
> For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
>
--
Miquel (a.k.a. Ktalà a.k.a. Ton)
Linux User #286784
GPG Key : 4D91EF7F
Debian GNU/Linux (Linux wolverine 2.6.23.1)
Welcome to the jungle, we got fun and games
Guns n'' Roses
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.