horseyguy
horseyguy

Reputation: 29895

How do i make a foreign/primary key case insensitive in rails

I'm using the following code:

in one model

class Foo < AR::Base
    has_many :bars, foreign_key: :email, primary_key: :email, dependent: :destroy
end

And in another model:

class Bar
    belongs_to :foo, foreign_key: :email, primary_key: :email
end

How do i make it so that the email is case insensitive as the foreign key and primary key for both models?

Upvotes: 1

Views: 521

Answers (1)

Iuri G.
Iuri G.

Reputation: 10630

I use utf8_unicode_ci collation for my tables (ci stands for case insensitive) which allows me to query without being concerned about the case of the text. If you make your table or at least column case insensitive, then it should just work with queries...

(Note this works for MySQL)

Upvotes: 1

Related Questions