我有与帖子相关的用户模型。
import tkinter as tk
master = tk.Tk()
numberframe = tk.Frame()
numberframe.grid(row=0, column=0)
button = {}
names = ('one', 'two', 'three', 'four', 'five',
'six', 'seven', 'eight', 'nine', 'zero')
for num, name in enumerate(names):
temp = tk.Button(master=numberframe,
text=(num+1)%10)
temp.grid(column=num%3,
row=num//3,
sticky='nsew')
button[name] = temp
operators = {}
operator_frame = tk.Frame()
operator_frame.grid(row=0, column=1)
operation = (('divide', '/'), ('multiply', '*'),
('subtract', '-'), ('add', '+'))
for name, sign in operation:
temp = tk.Button(master=operator_frame,
text=sign)
temp.grid()
operators[name] = temp
# example individually configure by the reference name.
button['seven'].configure(fg='red')
# example configure by group
for item in operators:
operators[item].configure(fg='red')
master.mainloop()
我需要从用户那里获得帖子的所有标记。为此,我编写了以下查询:class User(Base):
...
posts = relationship('Post',secondary=user2post, lazy="dynamic")
class Post(Base):
...
mark = Column(Integer)
,它向我返回了包含所有数据的帖子列表,就好像我没有写session.query(User).get(same_id).posts.options(load_only("mark")).all()
一样。
sqlalchemy的版本是1.2.11。
答案 0 :(得分:1)
从他们有关延迟列加载的文档中:
此功能允许仅在直接访问时才加载表的特定列,而不是在使用查询查询实体时加载。
查询发生后,访问返回的帖子确实被视为“直接访问”,因此orm将获取延迟的列