diff --git a/cqlengine/columns.py b/cqlengine/columns.py index e3413a08..af895023 100644 --- a/cqlengine/columns.py +++ b/cqlengine/columns.py @@ -99,7 +99,8 @@ class Column(object): default=None, required=False, clustering_order=None, - polymorphic_key=False): + polymorphic_key=False, + static=False): """ :param primary_key: bool flag, indicates this column is a primary key. The first primary key defined on a model is the partition key (unless partition keys are set), all others are cluster keys @@ -125,6 +126,7 @@ class Column(object): self.polymorphic_key = polymorphic_key #the column name in the model definition self.column_name = None + self.static = static self.value = None @@ -182,7 +184,8 @@ class Column(object): """ Returns a column definition for CQL table definition """ - return '{} {}'.format(self.cql, self.db_type) + static = "static" if self.static else "" + return '{} {} {}'.format(self.cql, self.db_type, static) def set_column_name(self, name): """ diff --git a/cqlengine/models.py b/cqlengine/models.py index cbb1485d..d725e42c 100644 --- a/cqlengine/models.py +++ b/cqlengine/models.py @@ -637,7 +637,6 @@ class ModelMetaClass(type): is_polymorphic_base = any([c[1].polymorphic_key for c in column_definitions]) column_definitions = [x for x in inherited_columns.items()] + column_definitions - polymorphic_columns = [c for c in column_definitions if c[1].polymorphic_key] is_polymorphic = len(polymorphic_columns) > 0 if len(polymorphic_columns) > 1: diff --git a/cqlengine/tests/management/test_management.py b/cqlengine/tests/management/test_management.py index 4c586eac..c2fb19af 100644 --- a/cqlengine/tests/management/test_management.py +++ b/cqlengine/tests/management/test_management.py @@ -1,5 +1,6 @@ - +import mock from cqlengine import ALL, CACHING_ALL, CACHING_NONE +from cqlengine.connection import get_session from cqlengine.exceptions import CQLEngineException from cqlengine.management import get_fields, sync_table, drop_table from cqlengine.tests.base import BaseCassEngTestCase, CASSANDRA_VERSION @@ -244,3 +245,30 @@ class NonModelFailureTest(BaseCassEngTestCase): def test_failure(self): with self.assertRaises(CQLEngineException): sync_table(self.FakeModel) + + +def test_static_columns(): + class StaticModel(Model): + id = columns.Integer(primary_key=True) + c = columns.Integer(primary_key=True) + name = columns.Text(static=True) + + drop_table(StaticModel) + + from mock import patch + + from cqlengine.connection import get_session + session = get_session() + + with patch.object(session, "execute", side_effect=Exception) as m: + try: + sync_table(StaticModel) + except: + pass + + assert m.call_count > 0 + statement = m.call_args[0][0].query_string + assert '"name" text static' in statement, statement + + + diff --git a/cqlengine/tests/model/test_model.py b/cqlengine/tests/model/test_model.py index 1bd143d0..9d4e0199 100644 --- a/cqlengine/tests/model/test_model.py +++ b/cqlengine/tests/model/test_model.py @@ -53,4 +53,6 @@ class BuiltInAttributeConflictTest(TestCase): class IllegalFilterColumnModel(Model): __keyspace__ = 'test' my_primary_key = columns.Integer(primary_key=True) - filter = columns.Text() \ No newline at end of file + filter = columns.Text() + + diff --git a/docs/topics/queryset.rst b/docs/topics/queryset.rst index d03a54a4..2466dece 100644 --- a/docs/topics/queryset.rst +++ b/docs/topics/queryset.rst @@ -464,7 +464,7 @@ QuerySet method reference Sets the field to order on. .. code-block:: python - + from uuid import uuid1,uuid4 class Comment(Model):