General Question about Data Duplication / Normalization (Modelling)
I have the following relationships:
- Foo
has_one
Bar - Bar
has_many
Baz - Foo
has_many
Baz through Bar
Now my problem: I need to work with Foo.Baz
but the information should be frozen/static.
By that I mean, whenever Bar.Baz
changes, I don't want Foo.Baz
to change.
In essence, Foo.Baz
is some kind of log record that describes Baz
at the time when Foo
was created.
How do I best deal with this situation?
My first inclination is to just create another relationship between 开发者_高级运维Foo
and Baz
but that would add a lot of redundant data because Bar.Baz
will only change very occasionally.
Is there a better way?
Could you leave it as it as and then create some scopes to get Foo.Baz based on the timestamps and not allow updates to Bar.Baz, just creates. So to get Foo.Baz, you'd get the latest
Bar.Baz when Bar.Foo == foo and Bar.baz.created_at < Foo.created_at.
I realize this isn't a great solution, but it may be a starting point...
精彩评论