Class: Comment
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
#id
Class Method Summary
collapse
Instance Method Summary
collapse
-
#article ⇒ Article?
belongs_to, from the foreign key article_id (or a belongs_to :article line): the article, or nil when there is none.
#==, after_create, after_destroy, after_save, after_update, #as_json, #attributes, before_create, before_destroy, before_save, before_update, before_validation, belongs_to, #destroy, encrypts, #errors, has_many, has_one, model_concern_insert_at, model_concern_insert_done, #new_record?, #persisted?, #reload, #save, #save!, scope, #to_json, #to_param, transaction, #update, #update_columns, upsert, #valid?, validate, validates, validates_foreign_key
Instance Attribute Details
The foreign key; 0 until set (references columns are null: false).
850
851
852
|
# File 'docs/api/stubs/generated_app.rb', line 850
def article_id
@article_id
end
|
#body ⇒ String?
845
846
847
|
# File 'docs/api/stubs/generated_app.rb', line 845
def body
@body
end
|
841
842
843
|
# File 'docs/api/stubs/generated_app.rb', line 841
def
@commenter
end
|
Class Method Details
832
|
# File 'docs/api/stubs/generated_app.rb', line 832
def self.all = CommentRelation.new("comments")
|
837
|
# File 'docs/api/stubs/generated_app.rb', line 837
def self.where(cond = nil, *binds) = all.where(cond, *binds)
|
Instance Method Details
belongs_to, from the foreign key article_id (or a
belongs_to :article line): the article, or nil when there is none. The
answer is kept for the article_id it was read for: the next call with
the same key runs no query, a changed key reads again, and
reload forgets it. When a column already has
the name, the reader is <stem>_as_<column> (author_as_author_id).
860
861
862
863
864
865
866
867
|
# File 'docs/api/stubs/generated_app.rb', line 860
def article
return @article_record if @article_loaded && @article_loaded_key == @article_id
@article_record = Article.find_by(id: @article_id)
@article_loaded = true
@article_loaded_key = @article_id
@article_record
end
|