You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently this code can raise in runtime with NilAssertionError if user.id is nil.
classUse
schema users do
pkey id : Int32endendclassPost
schema posts dotype author : User, key:"the_author_id"endendPost.where(author: user)
Post.update.set(author: user)
I propose to make things more explicit but reduce runtime errors in exchange. The .id referenced in queries is User variable, not its column name. The code would raise in compilation time if something is wrong:
Post.where("author.id": user.id!) # SELECT FROM posts WHERE the_author_id = ?Post.update.set("author.id": user.id!) # UPDATE posts SET the_author_id = ?
This could create confusion between explicit SQL variants, though. Such a query would raise in runtime, because posts table doesn't have author.idcolumn in the database schema:
Post.set("author.id", user.id!) # UPDATE posts SET author.id = ?
Possible workaround is bang query methods which mean explicit SQL, i.e.:
Post.set!("the_author_id", user.id)
User.where!("id IN ?, ?", {41, 42})
The text was updated successfully, but these errors were encountered:
Currently this code can raise in runtime with
NilAssertionError
ifuser.id
isnil
.I propose to make things more explicit but reduce runtime errors in exchange. The
.id
referenced in queries isUser
variable, not its column name. The code would raise in compilation time if something is wrong:This could create confusion between explicit SQL variants, though. Such a query would raise in runtime, because
posts
table doesn't haveauthor.id
column in the database schema:Possible workaround is bang query methods which mean explicit SQL, i.e.:
The text was updated successfully, but these errors were encountered: