Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在 Rails 中遇到了一个有趣的问题 假设我有一个模型,我想在它上面附加两个相同类型的模型,但这两个应该分开。
假设我们有一条狗,一条狗可以有训练师和主人,但训练师和主人都是人类餐桌的一部分。
假设 dog 表有 owner_id 和 trainer_id 引用外键
class Dog <AR::Base belongs_to :trainer,:class_name=>"Human",:foreign_key=>'trainer_id' belongs_to :owner,:class_name=>"Human",:foreign_key=>'owner_id' end
在 Python 3 中,我可以执行以下操作(另请参阅PEP3132 on Extended Iterable Unpacking):
a, *b = (1, 2, 3) # a = 1; b = (2, 3)