from sqlalchemy import Column, ForeignKey, Integer, UniqueConstraint
from sqlalchemy.dialects.mysql import TEXT
from sqlalchemy.orm import relationship

from libs.database.types import Base


class UserRoutine(Base):
    __tablename__ = 'user_routines'
    __table_args__ = (UniqueConstraint('user_id', 'routine_id', name='user_routine_unique'), )
    user_id = Column(Integer, ForeignKey('users.id', ondelete='SET NULL'), index=True)
    routine_id = Column(Integer, ForeignKey('routines.id', ondelete='SET NULL'), index=True)
    routine = relationship('Routine', lazy='selectin')
    amount = Column(TEXT)
    name = Column(TEXT) # 생성 당시의 routine 의 name 을 물려받아야 합니다.

    def json(self):
        return {
            'id': self.id,
            'user_id': self.user_id,
            'routine_id': self.routine_id,
            'routine_name': self.routine.name,
            'amount': self.amount,
        }

ad1ea10afca25832f97d2fd147271cf3e2a0b7f1
<mask token>


class UserRoutine(Base):
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>

<mask token>


class UserRoutine(Base):
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>

    def json(self):
        return {'id': self.id, 'user_id': self.user_id, 'routine_id': self.
            routine_id, 'routine_name': self.routine.name, 'amount': self.
            amount}

<mask token>


class UserRoutine(Base):
    __tablename__ = 'user_routines'
    __table_args__ = UniqueConstraint('user_id', 'routine_id', name=
        'user_routine_unique'),
    user_id = Column(Integer, ForeignKey('users.id', ondelete='SET NULL'),
        index=True)
    routine_id = Column(Integer, ForeignKey('routines.id', ondelete=
        'SET NULL'), index=True)
    routine = relationship('Routine', lazy='selectin')
    amount = Column(TEXT)
    name = Column(TEXT)

    def json(self):
        return {'id': self.id, 'user_id': self.user_id, 'routine_id': self.
            routine_id, 'routine_name': self.routine.name, 'amount': self.
            amount}

from sqlalchemy import Column, ForeignKey, Integer, UniqueConstraint
from sqlalchemy.dialects.mysql import TEXT
from sqlalchemy.orm import relationship
from libs.database.types import Base


class UserRoutine(Base):
    __tablename__ = 'user_routines'
    __table_args__ = UniqueConstraint('user_id', 'routine_id', name=
        'user_routine_unique'),
    user_id = Column(Integer, ForeignKey('users.id', ondelete='SET NULL'),
        index=True)
    routine_id = Column(Integer, ForeignKey('routines.id', ondelete=
        'SET NULL'), index=True)
    routine = relationship('Routine', lazy='selectin')
    amount = Column(TEXT)
    name = Column(TEXT)

    def json(self):
        return {'id': self.id, 'user_id': self.user_id, 'routine_id': self.
            routine_id, 'routine_name': self.routine.name, 'amount': self.
            amount}

from sqlalchemy import Column, ForeignKey, Integer, UniqueConstraint
from sqlalchemy.dialects.mysql import TEXT
from sqlalchemy.orm import relationship

from libs.database.types import Base


class UserRoutine(Base):
    __tablename__ = 'user_routines'
    __table_args__ = (UniqueConstraint('user_id', 'routine_id', name='user_routine_unique'), )
    user_id = Column(Integer, ForeignKey('users.id', ondelete='SET NULL'), index=True)
    routine_id = Column(Integer, ForeignKey('routines.id', ondelete='SET NULL'), index=True)
    routine = relationship('Routine', lazy='selectin')
    amount = Column(TEXT)
    name = Column(TEXT) # 생성 당시의 routine 의 name 을 물려받아야 합니다.

    def json(self):
        return {
            'id': self.id,
            'user_id': self.user_id,
            'routine_id': self.routine_id,
            'routine_name': self.routine.name,
            'amount': self.amount,
        }
