Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Association versioning with ignore_log_data and at(version: ) doesn't return expected results #214

Open
jasonlor opened this issue Aug 29, 2022 · 5 comments

Comments

@jasonlor
Copy link

jasonlor commented Aug 29, 2022

Using Logidze 1.2.2

Associations versioning using at(version: ##) and doesn't return the expected records.

Model.find(#).at(version: #).associated_model.with_log_data

Logidze.associations_versioning = true
Logidze.ignore_log_data_by_default = true
@jasonlor jasonlor changed the title Reset and backfill Reset and backfill in one command Aug 29, 2022
@jasonlor jasonlor changed the title Reset and backfill in one command Association versioning with ignore_log_data and at(version: ) doesn't return expected results Aug 30, 2022
@palkan
Copy link
Owner

palkan commented Aug 31, 2022

Hey, could you please provide more details? Ideally, the records log_data values, what you see and what you expect.

@palkan palkan added the awaiting response Awaiting reporter's response label Aug 31, 2022
@jasonlor
Copy link
Author

jasonlor commented Sep 1, 2022

I'm trying to retrieve the log_data from associated records using the following:

Initially, I have a setup where ParentModel's log_version=3. The updated_at was modified twice when the two ChildModel's were associated to it.

class ParentModel
  has_logidze
  has_many :child_models
end

class ChildModel
  has_logidze
  belongs_to :parent_model, touch: true
end

ParentModel - log_version = 3 -

  • ChildModel A - log_version = 1, quantity = 1
  • ChildModel B - log_version = 1, quantity = 1

ParentModel - log_version = 4

  • ChildModel A - log_version = 2, quantity = 1 -> 3
  • ChildModel B - log_version = 1, quantity = 1

I'm trying to retrieve the the value of ChildModel A when the ParentModel is at log_version=3. For ChildModel A I'm expecting a return value of 1. But when I'm seeing

ParentModel.find(#).at(version: 3).associated_model.with_log_data.child_models.find(ChildModelA.id)

ChildModelA's quantity field returns 3 (the latest value) instead of the 1 from log_data.

I've also tried:

lookup_time = ParentModel.find(#).at(version: 3).updated_at
ParentModel.find(#).at(time: lookup_time).associated_model.with_log_data.child_models

@palkan palkan added Investigation Required hacktoberfest It's pumpkin time! and removed awaiting response Awaiting reporter's response labels Sep 20, 2022
@palkan
Copy link
Owner

palkan commented Sep 20, 2022

Thanks for the details! Will take a look ASAP (or will try to find someone to fix this 🙂)

@jerometremblay
Copy link

jerometremblay commented Mar 15, 2023

I am not sure this is the exact same problem, however there is something wrong withe latest version.

Let say i have this

  • parent v1
    • child v1

when i read parent.at(version: 1).child it will return child v1
if i update child, giving

  • parent v1
    • child v2

then parent.at(version: 1).child will return child v2

However, after i update parent again, leading to

  • parent v2
    • child v2

now, reading parent.at(version: 1).child will correctly return child v1 that was there at the creation of parent v1.

@palkan
Copy link
Owner

palkan commented Mar 29, 2023

Under the hood, we use at(time:) when loading associations. I think, that can be the reason for inconsistency.

That's why I need log_data contents to figure out what went wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants