タケユー・ウェブ日報

Ruby on Rails や Flutter といったWeb・モバイルアプリ技術を武器にお客様のビジネス立ち上げを支援する、タケユー・ウェブ株式会社の技術ブログです。

2015-02-03から1日間の記事一覧

ActiveRecord で limit とか offset とかしたコレクションから条件を満たす全件数を取得する

posts = Post.where(author: author).limit(limit).offset(offset) posts.count # => 0 ~ limit posts.except(:limit, :offset).count # => 0 ~ Rails3からexceptで適用済みの条件式を除外できる。 except - リファレンス - Railsドキュメント

ActiveRecord::Relation から ActiveRecordクラス を得るには klass でOK?

posts= Posts.limit(limit).offset(offset) posts.klass # => Post(id: integer, title: string, body: text)