Skip to content
This repository has been archived by the owner on Jan 18, 2020. It is now read-only.

Incorrect primary key field used for right-hand table in join #6

Closed
bruth opened this issue Jan 9, 2013 · 1 comment
Closed

Incorrect primary key field used for right-hand table in join #6

bruth opened this issue Jan 9, 2013 · 1 comment

Comments

@bruth
Copy link
Contributor

bruth commented Jan 9, 2013

Changing the following line https://github.com/cbmi/modeltree/blob/master/modeltree/tree.py#L174 to self.pk_column fixed the issue in the below models.

The offending code:

from django.db import models

class Specimen(models.Model):
    aliquot_id = models.DecimalField(decimal_places=0, max_digits=16, db_column='ALIQUOT_ID', primary_key=True) # Field name made lowercase.
    # snip...
    class Meta:
        db_table = u'specimen'
        verbose_name = 'specimen'
        verbose_name_plural = 'specimens'

class Subject(models.Model):
    study_id = models.TextField(primary_key=True, db_column='study_id')
    # snip...
    class Meta:
        db_table = u'subject'
        verbose_name = 'subject'
        verbose_name_plural = 'subjects'


class Link(models.Model):
    aliquot_id = models.ForeignKey(Specimen, db_column='ALIQUOT_ID', primary_key=True)
    study_id = models.ForeignKey(Subject, db_column='study_id')
    # snip...
    class Meta:
        db_table = u'link'
@bruth
Copy link
Contributor Author

bruth commented Jan 9, 2013

Holy sh*t. This has not been noticed simply because both tables in most joins that had been defined/tested have the same primary key field.. id.

@bruth bruth closed this as completed in fac9ff9 Jan 9, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant