我有几个班级(即book
和user
)。我需要通过将book
广告位设置为lended
并将其t
设置为借款人的lended-to
来更新id
。
我使用Postmodern作为PostgreSQL数据库的后端
这就是我提出的(我希望名字足够自我描述)
(defmethod lend-book ((to-lend book) borrower) ;borrower is a user instance
(if (book-lent to-lend)
nil
(let (to-lend (get-dao 'book (book-id to-lend)))
(setf (book-lent-to to-lend) (user-id borrower))
(setf (book-lent to-lend) t)
(update-dao to-lend))))
但对我来说似乎太迫切了。
是否有更实用的方法可以做到这一点,或者后现代会阻碍它吗?
答案 0 :(得分:2)
您正在修改状态,这就是您所写的内容。我认为这是惯用的。
我发现您的代码存在两个问题:
defmethod
混淆了lambda列表:它应该是(to-lend book)
,而不是相反。这应该给出一些警告或错误。book-lent
和book-lent-to
。