本文整理汇总了Python中repo.Repo.table_name方法的典型用法代码示例。如果您正苦于以下问题:Python Repo.table_name方法的具体用法?Python Repo.table_name怎么用?Python Repo.table_name使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类repo.Repo
的用法示例。
在下文中一共展示了Repo.table_name方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _related_args
# 需要导入模块: from repo import Repo [as 别名]
# 或者: from repo.Repo import table_name [as 别名]
def _related_args(self, record, related_class):
# Both records are already persisted (have ids), so we can
# set up the relating record fully now. One of the ids comes
# from the constraint on the query, the other comes from
# the foreign key logic below:
# What we do is we get the singular table name of the record.
# With that, we can look into the related class description for
# the correct foreign key, which is set to the passed record's
# id.
record_class_name = inflector.singularize(Repo.table_name(record.__class__))
related_args = self.where_query.get(Repo.table_name(related_class), {})
related_key = associations.foreign_keys_for(related_class)[record_class_name]
related_args[related_key] = record.id
return related_args
示例2: __init__
# 需要导入模块: from repo import Repo [as 别名]
# 或者: from repo.Repo import table_name [as 别名]
def __init__(self, **kwargs):
"""
Instantiate a new object, mass-assigning the values in +kwargs+.
Cannot mass-assign id or created_at.
"""
if set(["id", "created_at", "updated_at"]) & set(kwargs):
raise AttributeError("Cannot set 'id', 'created_at', "
"or 'updated_at'")
for attr in self.__class__.__all_attributes__:
setattr(self, "_" + attr, None)
self.update(**kwargs)
self._id = None
self.__table = Repo.table_name(self.__class__)
self._related_records = []
self._delete_related_records = []
示例3: save
# 需要导入模块: from repo import Repo [as 别名]
# 或者: from repo.Repo import table_name [as 别名]
def save(self):
"""
Save a record to the database, creating it if needed, updating it
otherwise. Also saves related records (children and dependents) as
needed.
"""
with Repo.db:
self._do_save()
our_name = inflector.singularize(Repo.table_name(self.__class__))
for record in self._related_records:
if not self._id:
related_key = associations.foreign_keys_for(
record.__class__)[our_name]
setattr(record, related_key, self.__id)
record._do_save()
for record in self._delete_related_records:
record._do_destroy()
self._finish_save()
示例4: __init__
# 需要导入模块: from repo import Repo [as 别名]
# 或者: from repo.Repo import table_name [as 别名]
def __init__(self, model, record=None):
"""
Instantiates a new Query. +model+ is the lazy_record model (i.e. class)
that the query will be made about: the query's member objects will be
members of +model+'s class. When +record+ is passed, it is used for
managing related records (to ensure that associated records are upated
on +record+'s save and visa-versa).
"""
self.model = model
self.record = record
self.where_query = {}
self.custom_where = []
self.having_args = []
self.join_args = []
self._order_with = {}
self.group_column = None
self.limit_count = None
self.attributes = ["id"] + list(self.model.__all_attributes__)
self.table = Repo.table_name(self.model)
示例5: do_join
# 需要导入模块: from repo import Repo [as 别名]
# 或者: from repo.Repo import table_name [as 别名]
def do_join(table, model):
while model is not associations.model_from_name(table):
# ex) Category -> Forum -> Thread -> Post
# Category: {"posts": "forums"}
# Forum: {"posts": "threads"}
# Thread: {"posts": None}
# >>> Category.joins("posts")
# => [
# {'table': 'forums', 'on': ['category_id', 'id']}
# {'table': 'threads', 'on': ['forum_id', 'id']}
# {'table': 'posts', 'on': ['thread_id', 'id']}
# ]
if table in associations.associations_for(model):
# This to next: one-many (they have the fk)
# If associations.associations_for(model)[table] is None, then this is
# terminal (i.e. table is the FINAL association in the
# chain)
next_level = associations.associations_for(model)[table] or table
next_model = associations.model_from_name(next_level)
foreign_key = associations.foreign_keys_for(model).get(
next_level,
inflector.foreignKey(model.__name__))
yield {'table': next_level, 'on': [foreign_key, 'id']}
else:
# One-One or Many-One
# singular table had better be in associations.associations_for(model)
singular = inflector.singularize(table)
next_level = associations.associations_for(model)[singular] or singular
next_model = associations.model_from_name(next_level)
this_table_name = Repo.table_name(model)
foreign_key = associations.foreign_keys_for(model).get(
next_level,
inflector.foreignKey(model.__name__))
if associations.model_has_foreign_key_for_table(table,
model):
# we have the foreign key
order = ['id', foreign_key]
else:
# They have the foreign key
order = [foreign_key, 'id']
yield {'table': inflector.pluralize(next_level), 'on': order}
model = next_model
示例6: foreign_key
# 需要导入模块: from repo import Repo [as 别名]
# 或者: from repo.Repo import table_name [as 别名]
def foreign_key(local, foreign):
local_class = local.__class__
foreign_class = foreign.__class__
return associations.foreign_keys_for(local_class
)[inflector.singularize(Repo.table_name(foreign_class))]
示例7: test_gets_table_name
# 需要导入模块: from repo import Repo [as 别名]
# 或者: from repo.Repo import table_name [as 别名]
def test_gets_table_name(self, _):
table_name = Repo.table_name(TunaCasserole)
self.assertEqual("tuna_casseroles", table_name)