Skip to content
This repository has been archived by the owner on Feb 7, 2019. It is now read-only.

Filter on fk rels #50

Merged
merged 5 commits into from
Feb 2, 2015
Merged

Filter on fk rels #50

merged 5 commits into from
Feb 2, 2015

Conversation

maennel
Copy link
Contributor

@maennel maennel commented Jan 29, 2015

Added TestCase specified in issue #45 and bugfixed the code.
Now, ForeignKey relations get joined on the identity property of objects, such that time-constraint keep their effect of selecting a version of an object.

Also fixed a bug which had as an effect that time-constraints got added multiple time to a queryset (in fact, everytime get_compiler() on a VersionedQuerySet got called. Even if doing this doesn't invalidate the produced SQL, it gets hardly readable over time.

Finally, improved some comments on unit tests, in order to be able to recognize the absolute state of the system at any point in time t0-tn.

…M2M-relationships in order to be able to make the difference between the two of them. This enables us to JOIN on the identity field instead of the id field in case of a VersionedForeignKey
@@ -557,8 +584,8 @@ def create_versioned_many_to_many_intermediary_model(field, cls, field_name):
return type(str(name), (Versionable,), {
'Meta': meta,
'__module__': cls.__module__,
from_: VersionedForeignKey(cls, related_name='%s+' % name),
to_field_name: VersionedForeignKey(to, related_name='%s+' % name),
from_: VersionedForeignKey(cls, related_name='%s+' % name, auto_created=name),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this abusing the auto_created property? I'm not really familiar with auto_created. I'm just concerned if it will cause problems in some situations if it's not being used as Django expects; what comes to mind is migrations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure whether it's ABusing the auto_created property (which implies, that I'm not super familiar with the auto_created property).
Resources that I've found are:

Depending on what 'created' means, our use case may not be that wrong.
Also considering Django sets the auto_created flag on intermediary models in M2M relationships, why not setting it on its ForeignKeys? (It's true that I'm a bit worried that Django doesn't set that flag on ForeignKeys being part of auto_created intermediary models.)

However, side effects would need to be stress tested. Migrations are a good keyword.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking through Django's source code, I think it's safe. And the only other alternative that I see would be to add another property to the VersionedForeignKey class (e.g. is_m2m_field).
I'm surprised that we can't tell that it's an intermediary table somehow.

@brki brki merged commit 30b86d2 into master Feb 2, 2015
@brki brki deleted the filter-on-fk-rels branch February 2, 2015 16:30
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants