On Wednesday, June 24, 2015 at 3:21:39 PM UTC+3, simon2k wrote:
> Hi guys,
>
>
> The story is that I have two models Survey & Email Template as defined in a sample app:
>
>
> https://gist.github.com/simon2k/5b4d4043d4b625984ca1
>
>
> When I'm calling `survey.email_templates`, it fails, and I have the following error:
>
>
> ActiveRecord::StatementInvalid: PG::UndefinedFunction: ERROR: operator does not exist: character varying = integer
>
> LINE 1: ...M "email_templates" WHERE "email_templates"."survey_id" = 1
> ^
> HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
> : SELECT "email_templates".* FROM "email_templates" WHERE "email_templates"."survey_id" = 1
>
>
> I'm not sure whether I should treat it as a rails bug, and that rails should quote this integer, or not. I could look further into AR, if you feel, that this case should be handled. Otherwise, I'll be looking for a different solution for this challenge.
>
>
Why is survey id a string column? I believe AR is casting as an integer because the column being compared with is an integer (your primary key on the other table). Not doing this cast has been at the root of security problems in the past if my memory is correct.
Fred
> Also, I may mention source of this issue. Earlier our app was on EngineYard, where we had custom casting for this, so whenever there was an integer, it was casted into a string. Then we moved to RDS AWS, and unfortunately there we can't create castings. I dropped all of them, and I found this case. So I thought that it might be treated as a rails bug.
>
>
> Regards,
> Simon
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/5a73593b-a67c-4a6f-96a9-3f55f77841c9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment