Passed
Push — main ( 46dff7...b74274 )
by torrua
01:45
created

loglan_db.model_db.base_key   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 60
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A BaseKey.definitions() 0 3 1
1
# -*- coding: utf-8 -*-
2
# pylint: disable=C0303
3 1
"""
4
This module contains a basic Key Model
5
"""
6 1
from loglan_db import db
7 1
from loglan_db.model_db import t_name_keys
8 1
from loglan_db.model_init import InitBase, DBBase
9 1
from loglan_db.model_db.base_connect_tables import t_connect_keys
10
11 1
__pdoc__ = {
12
    'BaseKey.definitions':
13
        """*Relationship query for getting a list of definitions related to this key*
14
15
    **query** : Optional[List[BaseDefinition]]""",
16
    'BaseKey.created': False, 'BaseKey.updated': False, }
17
18
19 1
class BaseKey(db.Model, InitBase, DBBase):
20
    """Base Key's DB Model
21
22
    Describes a table structure for storing information
23
    about key words of the word's definitions.
24
    Some key words could belong to many definitions
25
    and some definitions could have many key words.
26
    That's why the relationship between Key
27
    and Definition should be many-to-many. See `t_connect_keys`.
28
29
    There is additional `word_language` UniqueConstraint here.
30
31
    <details><summary>Show Examples</summary><p>
32
    ```python
33
    {'language': 'en', 'word': 'aura', 'id': 1234}
34
35
    {'language': 'en', 'word': 'emotionality', 'id': 4321}
36
    ```
37
    </p></details>
38
    """
39 1
    __tablename__ = t_name_keys
40 1
    __table_args__ = (
41
        db.UniqueConstraint('word', 'language', name='_word_language_uc'), )
42
43 1
    id = db.Column(db.Integer, primary_key=True)
44
    """*Key's internal ID number*  
45
        **int** : primary_key=True"""
46 1
    word = db.Column(db.String(64), nullable=False, unique=False)
47
    """*Key's vernacular word*  
48
        **str** : max_length=64, nullable=False, unique=False  
49
    It is non-unique, as words can be the same in spelling in different languages"""
50 1
    language = db.Column(db.String(16), nullable=False, unique=False)
51
    """*Key's language*  
52
        **str** : max_length=16, nullable=False, unique=False"""
53
54 1
    _definitions = db.relationship(
55
        "BaseDefinition", secondary=t_connect_keys, lazy='dynamic', back_populates="_keys")
56
57 1
    @property
58
    def definitions(self):
59
        return self._definitions
60