Ruby on Rails
Wednesday, June 24, 2015
On Wednesday, June 24, 2015 at 8:21:39 AM UTC-4, simon2k wrote:ActiveRecord::Schema.define docreate_table :surveys, force: true do |t|
endcreate_table :email_templates, force: true do |t|t.integer :survey_idendendThe auto-generation of primary key in surveys is data type integer. Therefore the foreign key data type in email_templates should match.
In your models, you might want to declare:self.primary_key = 'id'. But I don't think it's necessary.
Just to be sure, you should probably go to your database and verify the contents of your tables:
sql> use 'your databasename'
sql> describe surveys;
sql> describe email_templates;
sql> SELECT surveys. * , email_templates. *
FROM surveys
INNER JOIN email_templates ON surveys.id = email_templates.survey_id
In irb> Survey.email_templates.to_sql ... might be helpful as well for verification
Hope this helps
Hi guys,The story is that I have two models Survey & Email Template as defined in a sample app: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" = 1I'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.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/7239886c-51ca-4011-a7f8-c4d4aa613dcd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment