# Path: invenio_communities/communities/records/models.py
# class CommunityMetadata(db.Model, RecordMetadataBase):
#     """Represent a community."""
# 
#     __tablename__ = 'communities_metadata'
# 
#     # Enables SQLAlchemy-Continuum versioning
#     __versioned__ = {}
# 
#     bucket_id = db.Column(UUIDType, db.ForeignKey(Bucket.id))
#     bucket = db.relationship(Bucket)


from invenio_db import db
from invenio_requests.records.models import RequestMetadata
from sqlalchemy.ext.declarative import declared_attr
from sqlalchemy_utils.types import UUIDType
from ...communities.records.models import CommunityMetadata
# -*- coding: utf-8 -*-
#
# Copyright (C) 2021 CERN.
#
# Invenio-Communities is free software; you can redistribute it and/or
# modify it under the terms of the MIT License; see LICENSE file for more
# details.




class CommunityRelationMixin:
    """Model mixin to define a relationship between a communities and records.

    Usage:

    .. code-block:: python

        class CommunityRecordM2M(db.Model, CommunityRelationMixin):
            __record_model__ = MyParentRecord
    """

    __record_model__ = None
    __request_model__ = None

    @declared_attr
    def community_id(cls):
        """Foreign key to the related communithy."""
        return db.Column(
            UUIDType,

# Path: invenio_communities/communities/records/models.py
# class CommunityMetadata(db.Model, RecordMetadataBase):
#     """Represent a community."""
# 
#     __tablename__ = 'communities_metadata'
# 
#     # Enables SQLAlchemy-Continuum versioning
#     __versioned__ = {}
# 
#     bucket_id = db.Column(UUIDType, db.ForeignKey(Bucket.id))
#     bucket = db.relationship(Bucket)


# Path: invenio_communities/records/records/models.py
from invenio_db import db
from invenio_requests.records.models import RequestMetadata
from sqlalchemy.ext.declarative import declared_attr
from sqlalchemy_utils.types import UUIDType
from ...communities.records.models import CommunityMetadata

# -*- coding: utf-8 -*-
#
# Copyright (C) 2021 CERN.
#
# Invenio-Communities is free software; you can redistribute it and/or
# modify it under the terms of the MIT License; see LICENSE file for more
# details.




class CommunityRelationMixin:
    """Model mixin to define a relationship between a communities and records.

    Usage:

    .. code-block:: python

        class CommunityRecordM2M(db.Model, CommunityRelationMixin):
            __record_model__ = MyParentRecord
    """

    __record_model__ = None
    __request_model__ = None

    @declared_attr
    def community_id(cls):
        """Foreign key to the related communithy."""
        return db.Column(
            UUIDType,

            db.ForeignKey(CommunityMetadata.id, ondelete="CASCADE"),