I have a model, lets say Ad, which I plan to fetch 2 datasets from, then merge them into 1. Is this possible:
ads = Ad.where(etc).limit(5)
if ads.length < 5
merge = Ad.where(etc).limit(remainder)
// merge both here
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
ActiveRecord allows you to do chaining. Try this out, it will execute only one query.
But in your case, you call the
lengthmethod so it will execute two queries. However, you can still do chaining. Usercountmethod is better thanlengthmethod becausecountwill send aCOUNT(*)to your database (faster).lengthwill load all records based on thewhereconditions and do a count on array (slower).