GithubHelp home page GithubHelp logo

Comments (6)

DmitryTsepelev avatar DmitryTsepelev commented on July 4, 2024 2

Makes sense. I'll take a closer look later this week, @dmills-yesware thanks for pointing this out!

from logidze.

palkan avatar palkan commented on July 4, 2024

When you call p.comments.length the comments association is not loaded yet, so we try to load it and rewind the state calling the #at method.

And it fails since the ignore_log_data is true for the Comment.

You need to use with_log_data here as well, i.e. p.comments.with_log_data.length.

Which seems confusing.

@DmitryTsepelev Maybe, we should apply with_log_data to associations automatically if log_data is defined for the owner?

from logidze.

dmills-yesware avatar dmills-yesware commented on July 4, 2024

Thanks for the quick response!

You need to use with_log_data here as well, i.e. p.comments.with_log_data.length

Ah, excellent. I had tried that, but not before first trying to load comments on the instance without using with_log_data.

[34] pry(main)> p.comments.length
ActiveModel::MissingAttributeError: missing attribute: log_data
from /Users/dmills/.rvm/gems/ruby-2.3.5@yesware/gems/activerecord-4.2.10/lib/active_record/attribute_methods/read.rb:93:in `block in _read_attribute'
[35] pry(main)> p.comments.with_log_data.length
ActiveModel::MissingAttributeError: missing attribute: log_data
from /Users/dmills/.rvm/gems/ruby-2.3.5@yesware/gems/activerecord-4.2.10/lib/active_record/attribute_methods/read.rb:93:in `block in _read_attribute'

As long as the first attempt to load the relation includes with_log_data then it works:

[40] pry(main)> Post.with_log_data.last.at(time: Time.now).comments.with_log_data.at(time: Time.now).length
=> 3

Worth noting: It does appear that I need to repeat the at on the comments relation in order to get the correct historical view of the comments at the same point in time as the Post. That's probably expected with the way things are built, but it might also be cool if the API were made to load the relation using the same with_log_data and at setting as the parent model, so that it's seamless.

Thanks again.

from logidze.

palkan avatar palkan commented on July 4, 2024

It does appear that I need to repeat the at on the comments relation in order to get the correct historical view of the comments at the same point in time as the Post. That's probably expected with the way things are built

Looks like a bug. Associations should inherit the at value automatically.

from logidze.

DmitryTsepelev avatar DmitryTsepelev commented on July 4, 2024

@dmills-yesware FYI I think I have a solution as a part of my ongoing PR - I decided to avoid making a separate one because that PR touches ignore_log_data codebase a lot

from logidze.

DmitryTsepelev avatar DmitryTsepelev commented on July 4, 2024

Fixed in 0.10.0, @palkan I guess we can close this issue

from logidze.

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.