Closed v-swamy closed 8 years ago
Those are validation errors. Which model has the title
attribute on it?
Also, there's a badge on the Readme for the Gitter chat room (https://gitter.im/cerebris/jsonapi-resources) which is a better area to ask questions like this. But this issue is also fine.
Oh thank you! I'll use that next time. Actually I have no model with a title
attribute, I assumed that was part of the error object. Here's my schema file:
ActiveRecord::Schema.define(version: 20160823195558) do
create_table "articles", force: :cascade do |t|
t.string "name"
t.boolean "available"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "friends", force: :cascade do |t|
t.string "first_name"
t.string "last_name"
t.string "email"
t.string "twitter"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "loans", force: :cascade do |t|
t.text "notes"
t.integer "friend_id"
t.integer "article_id"
t.boolean "returned"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["article_id"], name: "index_loans_on_article_id"
t.index ["friend_id"], name: "index_loans_on_friend_id"
end
end
Sorry, I looked too quickly - title
is part of the error. So the question remains why are you getting the validation error on friend. Can you null out the friend using the rails console without an error?
Good idea! I tried setting loan.friend
to nil
in the console (where loan
is the loan mentioned above), but when I attempt to save the record, it is rolled back. How odd!
Had this same problem. Looks like its a new feature of rails 5, relationships are required by default.
http://blog.bigbinary.com/2016/02/15/rails-5-makes-belong-to-association-required-by-default.html
@Subtletree Thanks for the link. I added a local test for setting nil and even with Rails 5 it's not failing in the test suite. If I set optional to false it will fail. So it seems more complicated than that. Maybe there's a setting we have made that I'm not seeing.
Have you got config.active_record.belongs_to_required_by_default = false
set in your new_framework_defaults.rb
initializer? Apparently if a rails app is upgraded to rails 5 this is set to false to maintain compatibility.
@Subtletree Nothing in the test initialization, but if I explicitly set it to true the test does fail in rails 5. I added #817 to get the missing test in. Thanks again.
@v-swamy I'm going to close this issue since it doesn't look to be a problem in JR. Please reopen if you determine that it is indeed a JR issue.
Sorry for the late response - actually, setting config.active_record.belongs_to_required_by_default = false
seemed to solve the issue for me. Thank you for looking into it!
Hi -
Trying to learn the ins and outs of JSON API, so I'm working through Adolfo Builes e-book. My apologies if this is not the appropriate place but I'm not able to get a hold of the author and I'm at wits end!
Trying to clear a relationship with the below:
and getting below error:
But I have no validations on my Loan model:
Here's the Friend model:
Can anyone advise me why I'm getting the error? Thank you so much!
-Vik