module Avram::PrimaryKeyMethods

Defined in:


Instance Method Summary

Instance Method Detail

def ==(other : self) #

[View source]
def delete #

[View source]
def primary_key_name : Symbol | Nil #

[View source]
def reload : self #

Reload the model with the latest information from the database

This method will return a new model instance with the latest data from the database. Note that this does not change the original instance, so you may need to assign the result to a variable or work directly with the return value.


user = SaveUser.create!(name: "Original")
SaveUser.update!(user, name: "Updated")

# Will be "Original"
# Will return "Updated" # Will be "Updated"
# Will still be "Original" since the 'user' is the same model instance.

Instead re-assign the variable. Now 'name' will return "Updated" since
'user' references the reloaded model.
user = user.reload

[View source]
def reload(&) : self #

Same as #reload but allows passing a block to customize the query.

This is almost always used to preload additional relationships.


user = SaveUser.create(params)

# We want to display the list of articles the user has commented on, so let's #
# preload them to avoid N+1 performance issues
user = user.reload(&.preload_comments(

# Now we can safely get all the comment authors

Note that the yielded query is the BaseQuery so it will not have any methods defined on your customized query. This is usually fine since typically reload only uses preloads.

If you do need to do something more custom you can manually reload:

user = SaveUser.create!(name: "Helen")

[View source]
def to_param : String #

For integration with Lucky This allows an Avram::Model to be passed into a Lucky::Action to create a url/path

[View source]