module Jennifer::Model::Resource::AbstractClassMethods

Defined in:

jennifer/model/resource.cr

Instance Method Summary

Instance Method Detail

abstract def actual_table_field_count #

Returns table column counts grepped from the database.


[View source]
abstract def all #

Returns Jennifer::QueryBuilder::ModelQuery(T).

This method is an entry point for writing query to your resource.

Address.all
  .where { _street.like("%St. Paul%") }
  .union(
    Profile.all
      .where { _login.in(["login1", "login2"]) }
      .select(:contact_id)
  )
  .select(:contact_id)
  .results

[View source]
abstract def build(values : Hash | NamedTuple, new_record : Bool) #

[View source]
abstract def build #

[View source]
abstract def column_names : Array(String) #

Returns all non virtual field names

Is generated by .mapping macro.


[View source]
abstract def columns_tuple #

Returns named tuple of column metadata

Is generated by .mapping macro.


[View source]
abstract def field_count #

Returns field count.

Is generated by .mapping macro.


[View source]
abstract def field_names : Array(String) #

Returns array of field names

Is generated by .mapping macro.


[View source]
abstract def new(values : Hash(Symbol, Jennifer::DBAny) | NamedTuple) #

Accepts symbol hash or named tuple, stringifies it and calls constructor with string-based keys hash.

It calls after_initialize callbacks.

User.new({:name => "John Smith"})
User.new({name: "John Smith"})

[View source]
abstract def new(values : Hash(String, Jennifer::DBAny)) #

Creates object based on given string hash.

It calls after_initialize callbacks.

User.new({"name" => "John Smith"})

[View source]
abstract def primary #

Returns criterion for the resource primary field.

Is generated by .mapping macro.

User.primary.inspect # => #<Jennifer::QueryBuilder::Criteria:0x0 @field="id", @table="users">

[View source]
abstract def primary_field_name #

Returns primary field name.


[View source]
abstract def relation(name) #

Returns relation instance by given name.


[View source]
abstract def superclass #

Returns superclass for the current class.

class A < Jennifer::Model::Base
  # ...
end

class B < A
end

B.superclass # => A

[View source]
abstract def table_prefix #

Returns table prefix.

If nil (default) is returned - adds nothing.


[View source]