本文整理匯總了Python中structure.Structure.get_fk_referenced_table方法的典型用法代碼示例。如果您正苦於以下問題:Python Structure.get_fk_referenced_table方法的具體用法?Python Structure.get_fk_referenced_table怎麽用?Python Structure.get_fk_referenced_table使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類structure.Structure
的用法示例。
在下文中一共展示了Structure.get_fk_referenced_table方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _get_fk_data
# 需要導入模塊: from structure import Structure [as 別名]
# 或者: from structure.Structure import get_fk_referenced_table [as 別名]
def _get_fk_data(self, table_name, fk, fk_value):
reltable = Structure.get_fk_referenced_table(table_name, fk)
reltable_pk = Structure.get_primary_key(reltable)
if not self._cache.relation_exists(table_name, reltable):
sql = SQLBuilder(reltable)
sql.add_where_literal(Column(reltable, reltable_pk).in_(self._cache.get_all_keys(table_name, fk)))
data = Query().execute_and_fetch(**sql.build_select())
self._cache.save_relation(table_name, reltable, data)
return Row(self._cache.get_relation_row(reltable, reltable_pk, fk_value), reltable, self)
示例2: __getattr__
# 需要導入模塊: from structure import Structure [as 別名]
# 或者: from structure.Structure import get_fk_referenced_table [as 別名]
def __getattr__(self, attr):
self._check_deleted()
if Structure.is_foreign_key(self._table_name, attr):
if self._result_set:
return self._result_set._get_fk_data(self._table_name, attr, self.data[attr])
else:
reltable = Structure.get_fk_referenced_table(self._table_name, attr)
reltable_pk = Structure.get_primary_key(reltable)
sql = SQLBuilder(reltable)
sql.add_where_condition(reltable_pk, self.data[attr])
data = Query().execute_and_fetch(**sql.build_select())
return Row(data[0], reltable)
else:
self._check_relation_exists(attr)
pk = self._get_pk()
if self._result_set:
return self._result_set._get_rel_data(self._table_name, attr, pk, self.data[pk])
else:
self._restricted_table_attr = attr
from restricted import RestrictedTableSelect
return RestrictedTableSelect(attr, SQLBuilder(attr), self)