Github user mxmrlv commented on a diff in the pull request:
https://github.com/apache/incubator-ariatosca/pull/72#discussion_r104313124
--- Diff: aria/modeling/bases.py ---
@@ -0,0 +1,405 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""
+ARIA's storage.structures module
+Path: aria.storage.structures
+
+models module holds ARIA's models.
+
+classes:
+ * ModelMixin - abstract model implementation.
+ * ModelIDMixin - abstract model implementation with IDs.
+"""
+
+from sqlalchemy.orm import relationship, backref
+from sqlalchemy.orm.collections import attribute_mapped_collection
+from sqlalchemy.ext import associationproxy
+from sqlalchemy import (
+ Column,
+ ForeignKey,
+ Integer,
+ Text,
+ Table,
+)
+
+from . import utils
+from ..utils import formatting
+
+
+class ModelMixin(object):
+
+ @utils.classproperty
+ def __modelname__(cls):
# pylint: disable=no-self-argument
+ return getattr(cls, '__mapiname__', cls.__tablename__)
+
+ @classmethod
+ def id_column_name(cls):
+ raise NotImplementedError
+
+ @classmethod
+ def name_column_name(cls):
+ raise NotImplementedError
+
+ @classmethod
+ def foreign_key(cls, parent_table, nullable=False):
+ """
+ Return a ForeignKey object.
+
+ :param parent_table: Parent table name
+ :param nullable: Should the column be allowed to remain empty
+ """
+ return Column(Integer,
+ ForeignKey('{table}.id'.format(table=parent_table),
+ ondelete='CASCADE'),
+ nullable=nullable)
+
+ @classmethod
+ def relationship_to_self(cls,
+ column_name,
+ relationship_kwargs=None):
+ relationship_kwargs = relationship_kwargs or {}
+
+ remote_side = '{cls}.{remote_column}'.format(
+ cls=cls.__name__,
+ remote_column=cls.id_column_name()
+ )
+
+ primaryjoin = '{remote_side} == {cls}.{column}'.format(
+ remote_side=remote_side,
+ cls=cls.__name__,
+ column=column_name
+ )
+
+ return relationship(
+ cls._get_cls_by_tablename(cls.__tablename__).__name__,
+ primaryjoin=primaryjoin,
+ remote_side=remote_side,
+ post_update=True,
+ **relationship_kwargs
+ )
+
+ @classmethod
+ def one_to_many_relationship_to_self(cls,
--- End diff --
This one is only used in the type hierarchy structure. Maybe it'd be better
not to expose this method (just implement that logic only in `TypeBase`).
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---