0

i have a belongs_to / has_one relationship and am doing tracking/versioning with paper_trail gem. When i change attribute on has_one model the version is created on belongs_to side, but not on a side where i made a change.

To give an example: Student has_one Locker Locker belong_to Student

I can edit this relation from both sides and currently i can only version the Locker side (last students that used a locker). I also need an opposite history - what lockers did student use.

Of course this would be perfectly OK if everytime I hit update the version is created, but paper_trail is smart and makes a version only when attrbute is actually changed. As locker relation is not in student model the version is not created (although i have create dmy own meta info attributes to store additional information).

So, is there any way to do this and that it is not ugly :) (i could for example make a small change on some other attribute, like putting in a space or something so that version is created - but that is overkill and is fugly)

Thx

Mitja Čebokli
  • 385
  • 4
  • 14
  • You can do something like this: http://stackoverflow.com/questions/10653085/display-all-versions-of-individual-records-in-papertrail to try and get all versions of all lockers, reify each and push all who belong to a given student_id to an array. – Marcelo Risoli Oct 07 '14 at 13:16
  • But how would you then associate that array (elements) to an actual versions of student model? I need not only all the lockers of a student, but to append them to actual student versions. – Mitja Čebokli Oct 07 '14 at 17:19
  • You mean you want to know the instant locker-student relation at the time of any given student update action? – Marcelo Risoli Oct 07 '14 at 17:26
  • Yes, that is what I am aiming for. – Mitja Čebokli Oct 08 '14 at 06:43

0 Answers0