Class: Kwipper::Post
Constant Summary
Constants inherited
from Model
Model::DB_FILE_NAME, Model::DB_NAME, Model::ID_COLUMN, Model::UnknownAttribute
Instance Attribute Summary
Attributes inherited from Model
#id
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Model
all, attr_array_to_hash, column, count, create, db, destroy, #destroy, exists?, find, generate_id, hash_to_key_vals, #initialize, normalize_value_for_db, #save, sql, #sql, table_name, #update, update, where
Constructor Details
This class inherits a constructor from Kwipper::Model
Class Method Details
.recent(statement = "SELECT * FROM posts") ⇒ Object
7
8
9
|
# File 'app/models/post.rb', line 7
def self.recent(statement = "SELECT * FROM posts")
all(statement).sort_by { |post| Time.parse post.created_at }.reverse
end
|
Instance Method Details
19
20
21
|
# File 'app/models/post.rb', line 19
def
Comment.all "SELECT * FROM comments WHERE post_id = #{id}"
end
|
23
24
25
|
# File 'app/models/post.rb', line 23
def
Model.count "SELECT COUNT(id) FROM comments WHERE post_id = #{id}"
end
|
#faves_count ⇒ Object
27
28
29
|
# File 'app/models/post.rb', line 27
def faves_count
Model.count "SELECT COUNT(id) FROM post_favorites WHERE post_id = #{id}"
end
|
#user ⇒ Object
11
12
13
|
# File 'app/models/post.rb', line 11
def user
@user ||= User.find user_id
end
|
#username ⇒ Object
15
16
17
|
# File 'app/models/post.rb', line 15
def username
user.username
end
|