Home how to ensure the parent model doesn't save when child model validation fails
Reply: 0

how to ensure the parent model doesn't save when child model validation fails

user3774
1#
user3774 Published in September 20, 2018, 12:45 pm
class User < ApplicationRecord 
  has_many :books
  delegate :title,:pages,:paragraphs to: book_attributes
end

class Book < ApplicationRecord
  belongs_to :user
  validates :title, length: { maximum: 35}

end

when I create a User with the associated books even though the book validation is wrong ie I create a title with more than 35 characters the user is saved .

How do i ensure that the users aren't saved when the validation of the book model have failed .

share|improve this question

1 Answer 1

active oldest votes
up vote 0 down vote
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.37144 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO