Fetching wrong data in query in rails

user4827489

I have done this

def show_selected_students(selected_students, students)   
    student = students.map{|a| a.name}
    selected_students = selected_students.split(",")
    @student_selected = selected_students.map {|i| student[i.to_i] }
end

in students I am fetching given data

#<ActiveRecord::Relation [#<Student id: 1, name: "XYZ",>, #<Student id: 2,  name: "test1">, #<Student id: 3,  name: "cherry">, #<Student id: 4,  name: "mary">, #<Student id: 5,  name: "hary">, #<Student id: 35,  name: "hen">, #<Student id: 44,  name: "duck">, #<Student id: 62,  name: "try">]>

and in selected_students I am getting 2,3,4 Now I want to fetch those students whose id match with selected_students for this I had written this but it gives me this output ['cherry', 'mary', 'hary'] i.e id 3,4,5 but I want 2,3,4 Please guide me how to solve this. Thanx in advance.

Vishal JAIN

You can try this:

def show_selected_students(selected_students, students)       
  selected_students = selected_students.split(",")
  @student_selected = students.where(:id => selected_students).map{|a|a.name}
end

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

SQL Query fetching wrong rows

From Dev

SQL Query fetching wrong rows

From Dev

join query not fetching any data

From Dev

Grouping the data after fetching the query

From Dev

Nested query not fetching data correctly

From Dev

sql query error data not fetching data proprerly

From Dev

Call a method when fetching data in rails models

From Dev

Fetching data only for specified mapping in HQL query

From Dev

SQL query for fetching data from multiple tables

From Dev

Fetching form data through query string in flask

From Dev

Mysql query is not fetching data as i want

From Dev

Error in database class in data fetching query

From Dev

Fetching data issue using simple like query

From Dev

Fetching data only for specified mapping in HQL query

From Dev

PHP / MySQL - Query not fetching any data

From Dev

Fetching data from MySQL, problems with diferent query

From Dev

Fetching data from CloudKit with queries in a loop retrieves wrong data

From Dev

Fetching objects from core data entity retrieves wrong object

From Dev

Getting unspecified data while fetching data using mongoose find query

From Java

Showing the wrong data for SQL Query

From Dev

Wildcard query % fetches wrong data

From Dev

mysql query display wrong data?

From Dev

Rails, Fetching specific screen's data from Google Analytics

From Dev

Fetching array of data from DB using Rails 3

From Dev

Rails 4 joins query display the wrong resource

From Dev

create mysql query for fetching data in 3 days slotwise

From Dev

Parse background job query iterations are returning before fetching data

From Dev

Select query is not working while fetching data from database

From Dev

Fetching Data from XML along with the Conditions in a single Query

Related Related

  1. 1

    SQL Query fetching wrong rows

  2. 2

    SQL Query fetching wrong rows

  3. 3

    join query not fetching any data

  4. 4

    Grouping the data after fetching the query

  5. 5

    Nested query not fetching data correctly

  6. 6

    sql query error data not fetching data proprerly

  7. 7

    Call a method when fetching data in rails models

  8. 8

    Fetching data only for specified mapping in HQL query

  9. 9

    SQL query for fetching data from multiple tables

  10. 10

    Fetching form data through query string in flask

  11. 11

    Mysql query is not fetching data as i want

  12. 12

    Error in database class in data fetching query

  13. 13

    Fetching data issue using simple like query

  14. 14

    Fetching data only for specified mapping in HQL query

  15. 15

    PHP / MySQL - Query not fetching any data

  16. 16

    Fetching data from MySQL, problems with diferent query

  17. 17

    Fetching data from CloudKit with queries in a loop retrieves wrong data

  18. 18

    Fetching objects from core data entity retrieves wrong object

  19. 19

    Getting unspecified data while fetching data using mongoose find query

  20. 20

    Showing the wrong data for SQL Query

  21. 21

    Wildcard query % fetches wrong data

  22. 22

    mysql query display wrong data?

  23. 23

    Rails, Fetching specific screen's data from Google Analytics

  24. 24

    Fetching array of data from DB using Rails 3

  25. 25

    Rails 4 joins query display the wrong resource

  26. 26

    create mysql query for fetching data in 3 days slotwise

  27. 27

    Parse background job query iterations are returning before fetching data

  28. 28

    Select query is not working while fetching data from database

  29. 29

    Fetching Data from XML along with the Conditions in a single Query

HotTag

Archive