Class: Comment

Inherits:
Cybertrain::Model show all
Defined in:
docs/api/stubs/generated_app.rb

Overview

The other side of Article#comments: what spin run gen writes for a comments table with t.references :article (an article_id column and a foreign key to articles). It has the same finders as Article, through CommentRelation.

Instance Attribute Summary collapse

Attributes inherited from Cybertrain::Model

#id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Cybertrain::Model

#==, after_create, after_destroy, after_save, after_update, #as_json, #attributes, before_create, before_destroy, before_save, before_update, before_validation, #destroy, #errors, #new_record?, #persisted?, #reload, #save, #save!, #to_json, #to_param, #update, #valid?, validates

Instance Attribute Details

#article_id ⇒ Integer

The foreign key; 0 until set (references columns are null: false).

Returns:

  • (Integer)


362
363
364
# File 'docs/api/stubs/generated_app.rb', line 362

def article_id
  @article_id
end

#body ⇒ String?

Returns:

  • (String, nil)


357
358
359
# File 'docs/api/stubs/generated_app.rb', line 357

def body
  @body
end

#commenter ⇒ String?

Returns:

  • (String, nil)


353
354
355
# File 'docs/api/stubs/generated_app.rb', line 353

def commenter
  @commenter
end

Class Method Details

.all ⇒ CommentRelation

Returns:



344
# File 'docs/api/stubs/generated_app.rb', line 344

def self.all = CommentRelation.new("comments")

.where(conditions) ⇒ CommentRelation

Parameters:

  • conditions (Hash{Symbol => Object})

Returns:



349
# File 'docs/api/stubs/generated_app.rb', line 349

def self.where(conditions) = all.where(conditions)

Instance Method Details

#article ⇒ Article?

belongs_to, from the foreign key article_id: the article, or nil when there is none. A fresh query on every call. When a column already has the name, the reader is <stem>_as_<column> (author_as_author_id).

Returns:



369
# File 'docs/api/stubs/generated_app.rb', line 369

def article = Article.find_by(id: @article_id)