Question

My model is like this. I'm using Kaminari with Mongoid and set the default per page results.

class SavedTweet
    include Mongoid::Document

    field :slug,                :type => String
    field :created_at,          :type => DateTime, :default => Time.now

    has_many :tweets,           :order => :created_at.desc
end

class Tweet
    include Mongoid::Document

    paginates_per 30  #default per page

    field :tweet_id,            type: String
    field :html,                type: String
    field :created_at,          type: DateTime

    belongs_to :saved_tweet
end

And this is my query

SavedTweet.find_by(slug: "slug")

I'm expecting to get only 30 tweets to come back, but instead I get everything back. Am I missing something obvious?

Was it helpful?

Solution

You should use de page function:

SavedTweet.where(slug: "slug").page(1)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top