Commit ec481c60 authored by Tomas Taraba's avatar Tomas Taraba

3386 Define fks and relationship using built-in methods in table userlabels

parent d45def75
......@@ -14,10 +14,10 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
from sqlalchemy.schema import Column, ForeignKeyConstraint, PrimaryKeyConstraint
from sqlalchemy.types import Integer, String
from sqlalchemy.orm import relationship
from sqlalchemy import ForeignKey
from sqlalchemy.orm import relationship, backref
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer
from xivo_dao.helpers.db_manager import Base
......@@ -25,15 +25,10 @@ from xivo_dao.helpers.db_manager import Base
class UserLabels(Base):
__tablename__ = 'userlabels'
__table_args__ = (
PrimaryKeyConstraint('user_id', 'label_id'),
ForeignKeyConstraint(('user_id',),
('userfeatures.id',),
ondelete='RESTRICT'),
ForeignKeyConstraint(('label_id',),
('labels.id',),
ondelete='RESTRICT'),
)
user_id = Column(Integer, nullable=False)
label_id = Column(Integer, nullable=False)
\ No newline at end of file
id = Column(Integer, primary_key=True)
user_id = Column(Integer, ForeignKey('userfeatures.id', ondelete='RESTRICT'))
label_id = Column(Integer, ForeignKey('labels.id', ondelete='RESTRICT'))
user_features = relationship("UserFeatures", backref=backref("userlabels"))
labels = relationship("Labels", backref=backref("userlabels"))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment