aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fatcat/models.py4
-rw-r--r--fatcat/sql.py13
2 files changed, 10 insertions, 7 deletions
diff --git a/fatcat/models.py b/fatcat/models.py
index 6672ce2e..9abb286e 100644
--- a/fatcat/models.py
+++ b/fatcat/models.py
@@ -39,7 +39,7 @@ class ReleaseRef(db.Model):
__tablename__ = "release_ref"
id = db.Column(db.Integer, primary_key=True, nullable=False)
release_rev= db.Column(db.ForeignKey('release_revision.id'), nullable=False)
- target_release_id= db.Column(db.ForeignKey('release_id.id'), nullable=False)
+ target_release_id= db.Column(db.ForeignKey('release_id.id'), nullable=True)
index = db.Column(db.Integer, nullable=True)
stub = db.Column(db.String, nullable=True)
doi = db.Column(db.String, nullable=True)
@@ -122,9 +122,7 @@ class ReleaseRevision(db.Model):
issue = db.Column(db.String, nullable=True)
creators = db.relationship('ReleaseContrib', lazy='subquery')
- #backref=db.backref('releases', lazy=True))
refs = db.relationship('ReleaseRef', lazy='subquery')
- #backref=db.backref('backrefs', lazy=True))
class CreatorId(db.Model):
__tablename__ = 'creator_id'
diff --git a/fatcat/sql.py b/fatcat/sql.py
index c3c928a8..ad0a045f 100644
--- a/fatcat/sql.py
+++ b/fatcat/sql.py
@@ -184,10 +184,15 @@ def add_crossref(meta):
extra_json = ExtraJson(json=extra, sha1=hashlib.sha1(extra).hexdigest())
release.extra_json = extra_json.sha1
- # references (TODO)
- #refs = []
- #for rm in meta['reference']:
- # rm: author, volume, first-page, year, journal-title, DOI
+ # references
+ for i, rm in enumerate(meta.get('reference', [])):
+ ref = ReleaseRef(
+ release_rev=release.id,
+ doi=rm.get("DOI", None),
+ index=i+1,
+ # TODO: how to generate a proper stub here from k/v metadata?
+ stub="| ".join(rm.values()))
+ release.refs.append(ref)
db.session.add_all([work, work_id, release, release_id, container,
container_id, extra_json])