GithubHelp home page GithubHelp logo

Rails 5 about deep_cloneable HOT 14 CLOSED

dsounded avatar dsounded commented on July 29, 2024
Rails 5

from deep_cloneable.

Comments (14)

moiristo avatar moiristo commented on July 29, 2024

The test suite is being run on TravisCI using rails 5.0.0.1 and passes. Which version are you exactly talking about?

from deep_cloneable.

dsounded avatar dsounded commented on July 29, 2024

5.0.0.1 same, but my locals specs pass on Rails 4.2 and don't pass on 5

I am using 2.2.2 version

from deep_cloneable.

moiristo avatar moiristo commented on July 29, 2024

It might have to do with the new rails defaults for belongs_to. But I'm not sure. Do you think you can come up with a failing test case?

from deep_cloneable.

dsounded avatar dsounded commented on July 29, 2024

@moiristo
From what I see, there is another validation in Rails 5:

I've tried to debug here
lib/deep_cloneable.rb:88

kopy.associations.map(&:association_field) (where associations is just a has many relation)
[nil, nil, nil, nil]
same in Rails 4 and 5

But kopy.associations.map(&:valid?)
Rails 4:
[true, true, true, true]
Rails 5:
[false, false, false, false]

That's why it says not a number, 'cause it's nil

from deep_cloneable.

dsounded avatar dsounded commented on July 29, 2024

adding config.active_record.belongs_to_required_by_default = false into config didn't solve the problem

from deep_cloneable.

moiristo avatar moiristo commented on July 29, 2024

So it tells you that the associated objects are not valid. What are the errors? Can you do something like: kopy.associations.map{|record| record.valid?; record.errors.full_messages.join(',') } and see what the validation errors are?

from deep_cloneable.

dsounded avatar dsounded commented on July 29, 2024

@details={:association_id=>[{:error=>:not_a_number, :value=>nil}]},
@messages={:association_id=>["is not a number"]}

from deep_cloneable.

moiristo avatar moiristo commented on July 29, 2024

Ok, so kopy.associations points to a certain list of objects that contain a belongs_to somewhere that is stored in association_id. Does it work when you make that belongs_to optional?

from deep_cloneable.

dsounded avatar dsounded commented on July 29, 2024

Added optional: true to belongs_to relation, it doesn't work as well,
btw I have belongs_to with params class_name and foreign_key if it matters...

from deep_cloneable.

moiristo avatar moiristo commented on July 29, 2024

Hmm, it might be that rails5 handles things differently when nil is explicitly being passed to an association. Just a hunch.. I'll try to find out if I can reproduce the error in the test suite.

from deep_cloneable.

dsounded avatar dsounded commented on July 29, 2024

Doing the same on new rails 5 project

from deep_cloneable.

moiristo avatar moiristo commented on July 29, 2024

👍 please let me know when you know more!

from deep_cloneable.

dsounded avatar dsounded commented on July 29, 2024

After deeper digging into the problem I've seen it's my custom validation fails, sorry for that...

thanks for the gem, btw

from deep_cloneable.

moiristo avatar moiristo commented on July 29, 2024

Ok, thanks for the feedback!

from deep_cloneable.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.