All Questions
74 questions
1
vote
1
answer
515
views
How to concat query result of top N records from a group in MYSQL
I have the following query which gives the count of name grouped by user id in desc order. I have reached so far but cant go beyond that. I would like to concat the name column of top 2 records per ...
-1
votes
1
answer
271
views
Use Foreign key in where clause in Rails
I have 2 models
1 is request and second is passed
I have a has_one association between requests and passed like this
Request.rb
has_one :status
status.rb
belongs_to :request
in status I have a ...
0
votes
2
answers
55
views
How to query rails way ? Rails 3.2
List of relationship between models:
class ErrorScope < ActiveRecord::Base
belongs_to :server
has_many :scope_to_fixflow_map
attr_accessible :id, :server_id, :error_codes, :scoping_method, :...
1
vote
1
answer
107
views
Why is it a syntax error? [duplicate]
Simple query like this.
MyModel.where('student_id = :id AND from <= :date AND to >= :date', {:id => student.id, :date => day.to_s(:db)})
Returns an exception
=> ActiveRecord::...
1
vote
1
answer
568
views
Rails order product price ascending and descending by their minimum value has_many relation
I am trying to order my products by their price ascending and descending, but depending on the minimum value.
products `has_many` product_prices through product_offers.
I am using @products.includes(...
0
votes
1
answer
82
views
SQL query to select a User's friends via an associated model
My question is: for a given User, what SQL command could be used to select
all associated initiators/initiatees for which the associated Relation is confirmed and of a given type?
The Ruby is as ...
0
votes
0
answers
104
views
Sql for invoices with more than 50% paid
I'm breaking my head around this query for a while now so I thought I'd give it a shot here at SO.
I have the following tables:
quotes(id, quote_version_id, etc for brevity)
quote_versions(id, ...
0
votes
2
answers
96
views
how to make sql in Active relation which has subquery in from clause
I have to make a SQL query using Active Relation.
select * from (select * from purchase_order_items order by
created_at desc) as abc where (fsn = '9788183071000' and sku
='SKU0000000000000') ...
1
vote
1
answer
49
views
Trying to query rails database
I am trying to pull all orders from the database from two specific clients, everything I try in rails c gives me a error:
irb(main):008:0> clients = clients.find(name: "CLS_Trials")
NoMethodError: ...
0
votes
1
answer
636
views
how to generate month wise data report in rails 3
I Am new in rails, I have facing some problem regarding month wise data report.
I have a user table and transaction table with has_many association. transaction table has column type(buy or sell), ...
0
votes
1
answer
110
views
How to calculate the greater value of the average between has_many association in rails 3
I am new in rails,
I Have a Profile table and profile history table. Profile has many profile history.
Profile table has
id and current_count column and profile history has profile_id, and count ...
0
votes
1
answer
71
views
I want to write following query rails way
select DISTINCT firstname
from users u
inner join members m
on m.user_id = u.id
inner join member_roles m1
on m1.member_id = m.id
inner join roles r
on r.id = ...
1
vote
0
answers
67
views
Additional queries being performed from model connecting to a remote mysql database
Everytime i call any method in my model i see the following four additional queries being performed. The model name is City. And im connecting to a remote mysql legacy database using connection_ninja(...
0
votes
0
answers
57
views
accessing the values from a belongs_to table
I am trying to get the values from a belongs_to table in my controller (so i can use these values to insert into another model.
class AccesspointsController < ApplicationController
def create
...
0
votes
0
answers
58
views
Getting symbol @new_record,false,@readonly in rails query
How to avoid such symbol @new_record,false,@readonly from rails query
my result of hash is showing like that
[#<Hotel id: 42, hotel_name: "Vijay: Resort De Alturas,Candolim", stars: "4", location:...