class

Comment::BaseQuery

Inherits Avram::PrimaryKeyQueryable < Avram::Queryable < Enumerable < Reference < Object

Constructors

all

Class methods

any?

Returns true if at least one of the collection's members is truthy.

[nil, true, 99].any? # => true
[nil, false].any?    # => false
([] of Int32).any?   # => false
  • #present? does not consider truthiness of elements.
  • #any?(&) and #any(pattern) allow custom conditions.

NOTE: #any? usually has the same semantics as #present?. They only differ if the element type can be falsey (i.e. T <= Nil || T <= Pointer || T <= Bool). It's typically advised to prefer #present? unless these specific truthiness semantics are required.

find(id) : T
first

Returns the first element in the collection. Raises Enumerable::EmptyError if the collection is empty.

([1, 2, 3]).first   # => 1
([] of Int32).first # raises Enumerable::EmptyError
first?

Returns the first element in the collection. When the collection is empty, returns nil.

([1, 2, 3]).first?   # => 1
([] of Int32).first? # => nil
last
last?
new_with_existing_query(query : Avram::QueryBuilder)
none?

Returns true if all of the elements of the collection are falsey.

[nil, false].none?       # => true
[nil, false, true].none? # => false

It's the opposite of all?.

preload_user(record : Comment, force : Bool = false) : Comment
preload_user(record : Comment, force : Bool = false, &) : Comment
preload_user(record : Comment, preload_query : User::BaseQuery, force : Bool = false) : Comment
preload_user(records : Enumerable(Comment), force : Bool = false) : Array(Comment)
preload_user(records : Enumerable(Comment), force : Bool = false, &) : Array(Comment)
preload_user(records : Enumerable(Comment), preload_query : User::BaseQuery, force : Bool = false) : Array(Comment)
truncate(*, cascade : Bool = false, restart_identity : Bool = false)

Removes all data from a table using the TRUNCATE postgres SQL command.

You should run this command with cascade: true if your table columns are referenced by other foreign key constraints. Use delete instead if you don't want to accidentally delete rows referenced elsewhere.

To delete all data referenced by foreign keys as well, set cascade to true.

Instance methods

clone

Returns a copy of self with all instance variables cloned.

commentable_id(value)
commentable_id
commentable_type(value)
commentable_type
content(value)
content
created_at(value)
created_at
find(id) : T
full_join_user(where_user : User::BaseQuery)
full_join_user
id(value)
id
inner_join_user(where_user : User::BaseQuery)
inner_join_user
join_user(where_user : User::BaseQuery)
join_user
left_join_user(where_user : User::BaseQuery)
left_join_user
preload_user(preload_query : User::BaseQuery) : self
preload_user
preload_user
right_join_user(where_user : User::BaseQuery)
right_join_user
update(id : Int64 | Avram::Nothing = IGNORE, created_at : Time | Avram::Nothing = IGNORE, updated_at : Time | Avram::Nothing = IGNORE, content : String | Avram::Nothing = IGNORE, commentable_type : String | Avram::Nothing = IGNORE, commentable_id : Int64 | Avram::Nothing = IGNORE, user_id : User::PrimaryKeyType | Avram::Nothing = IGNORE) : Int64

Update the records using the query's where clauses, or all records if no wheres are added.

Returns the number of records updated as Int64.

# Update all comments with the word "spam" as spam
CommentQuery.new.body.ilike("spam").update(spam: true)
updated_at(value)
updated_at
user_id(value)
user_id
where_user(assoc_query : User::BaseQuery, auto_inner_join : Bool = true)

DEPRECATED Use any of the join methods with a where_user argument instead

Macros

generate_criteria_method(name, type)