Hi,
A suggestion without trying this out... If your number_of_full_time &
number_of_part_time are integers but are stored as strings then why
convert them? Remove the casting while indexing & just search on them
as strings:
Ngo.search :with => {:full_time_members => "12" }
The other option is of course to store them as integers if that is
what they always are ... but I guess you have a reason why you did it
this way.
Hope this helps,
Harry
On Nov 17, 1:44 pm, ketan deshmukh
<ketan3...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Hi, I am new with ruby on rails. I am working on a project. I which i
> have a model named "ngo.rb" and it has a "has_one"
association with
> another model named "ngo_staff.rb"
>
> Description of model :
>
> 1. Ngo
> ----------------------------------------------------------------
> - id
>
> - has_one :ngo_staff
>
> 2. NgoStaff
> -----------------------------------------------------------------
> - id
> - ngo_id
> - number_of_full_time (stored as "string" in database) (this
> value will always be an integer)
> - number_of_part_time (stored as "string" in database) (this
value
> will always be an integer)
>
> - belongs_to :ngo
>
> Now in the define_index method of Ngo.rb model
>
> --------------------------------------------------------------------------
>
> define_index do
> has "CAST(ngo_staffs(:number_of_part_time) AS INT)", :type
> => :integer, :as => :part_time_members
> has "CAST(ngo_staffs(:number_of_full_time) AS INT)", :type
> => :integer, :as => :full_time_members
> end
> end
>
> ---------------------------------------------------------------------------
>
> In my database :
>
> >> Ngo.all.count
> => 11
> >> Ngo.first.ngo_staff
>
> => #<NgoStaff id: 1, ngo_id: 1, number_of_full_time: "12",
> number_of_part_time: "65", number_of_volunteer: "567",
created_at:
> "2010-09-07 08:10:36", updated_at: "2010-09-07
08:10:36">
>
> but the following search query gives me all the 11 records as output
> but the expected output is only the first record.
>
> >> Ngo.search :with => {:full_time_members => 12 }
>
> => [#<Ngo id: 1, user_id: 2, acronym_name: "test_org1",
service_id: 0,
> operation_start_date: 2006, legal_structure: "Partnership",
> other_legal_structure: "", is_non_profit: "false",
logo_file_name:
> "chess-p.jpg", logo_content_type: "image/jpeg",
logo_file_size: 5501,
> has_funding_need: false, has_volunteer_need: false, is_visible: true,
> registration_documents: "nil", delta: false, created_at:
"2010-09-06
> 09:57:22", updated_at: "2010-11-17 10:05:47",
is_blacklisted: true,
> is_complete_info: true>, #<Ngo id: 2, user_id: 3, acronym_name:
> "test_org2", service_id: 0, operation_start_date: 2006,
> legal_structure: "Partnership", other_legal_structure:
"",
> is_non_profit: "false", logo_file_name: nil, logo_content_type:
nil,
> logo_file_size: nil, has_funding_need: false, has_volunteer_need:
> false, is_visible: true, registration_documents: "nil", delta:
false,
> created_at: "2010-09-06 09:57:22", updated_at: "2010-09-06
09:57:22",
> is_blacklisted: true, is_complete_info: true>, #<Ngo id: 3, user_id:
> 4, acronym_name: "test_org3", service_id: 0,
operation_start_date:
> 2006, legal_structure: "Partnership", other_legal_structure:
"",
> is_non_profit: "false", logo_file_name: nil, logo_content_type:
nil,
> logo_file_size: nil, has_funding_need: false, has_volunteer_need:
> false, is_visible: true, registration_documents: "nil", delta:
false,
> created_at: "2010-09-06 09:57:22", updated_at: "2010-09-06
09:57:22",
> is_blacklisted: true, is_complete_info: true>, #<Ngo id: 4, user_id:
> 5, acronym_name: "test_org4", service_id: 0,
operation_start_date:
> 2006, legal_structure: "Partnership", other_legal_structure:
"",
> is_non_profit: "false", logo_file_name: nil, logo_content_type:
nil,
> logo_file_size: nil, has_funding_need: false, has_volunteer_need:
> false, is_visible: true, registration_documents: "nil", delta:
false,
> created_at: "2010-09-06 09:57:22", updated_at: "2010-10-01
10:14:56",
> is_blacklisted: true, is_complete_info: true>, #<Ngo id: 5, user_id:
> 6, acronym_name: "test_org5", service_id: 0,
operation_start_date:
> 2006, legal_structure: "Partnership", other_legal_structure:
"",
> is_non_profit: "false", logo_file_name: nil, logo_content_type:
nil,
> logo_file_size: nil, has_funding_need: false, has_volunteer_need:
> false, is_visible: true, registration_documents: "nil", delta:
false,
> created_at: "2010-09-06 09:57:22", updated_at: "2010-09-13
13:03:06",
> is_blacklisted: true, is_complete_info: true>, #<Ngo id: 6, user_id:
> 7, acronym_name: "test_org6", service_id: 0,
operation_start_date:
> 2006, legal_structure: "Partnership", other_legal_structure:
"",
> is_non_profit: "false", logo_file_name: nil, logo_content_type:
nil,
> logo_file_size: nil, has_funding_need: false, has_volunteer_need:
> false, is_visible: true, registration_documents: "nil", delta:
false,
> created_at: "2010-09-06 09:57:22", updated_at: "2010-09-06
09:57:22",
> is_blacklisted: true, is_complete_info: true>, #<Ngo id: 7, user_id:
> 8, acronym_name: "test_org7", service_id: 0,
operation_start_date:
> 2006, legal_structure: "Partnership", other_legal_structure:
"",
> is_non_profit: "false", logo_file_name: nil, logo_content_type:
nil,
> logo_file_size: nil, has_funding_need: false, has_volunteer_need:
> false, is_visible: true, registration_documents: "nil", delta:
false,
> created_at: "2010-09-06 09:57:22", updated_at: "2010-09-06
09:57:22",
> is_blacklisted: true, is_complete_info: true>, #<Ngo id: 8, user_id:
> 9, acronym_name: "test_org8", service_id: 0,
operation_start_date:
> 2006, legal_structure: "Partnership", other_legal_structure:
"",
> is_non_profit: "false", logo_file_name: nil, logo_content_type:
nil,
> logo_file_size: nil, has_funding_need: false, has_volunteer_need:
> false, is_visible: true, registration_documents: "nil", delta:
false,
> created_at: "2010-09-06 09:57:22", updated_at: "2010-09-06
09:57:22",
> is_blacklisted: true, is_complete_info: true>, #<Ngo id: 9, user_id:
> 10, acronym_name: "test_org9", service_id: 0,
operation_start_date:
> 2006, legal_structure: "Partnership", other_legal_structure:
"",
> is_non_profit: "false", logo_file_name: "nil",
logo_content_type: nil,
> logo_file_size: nil, has_funding_need: false, has_volunteer_need:
> false, is_visible: true, registration_documents: "nil", delta:
false,
> created_at: "2010-09-06 09:57:22", updated_at: "2010-09-06
09:57:22",
> is_blacklisted: true, is_complete_info: true>, #<Ngo id: 10, user_id:
> 35, acronym_name: nil, service_id: nil, operation_start_date: nil,
> legal_structure: nil, other_legal_structure: nil, is_non_profit: nil,
> logo_file_name: nil, logo_content_type: nil, logo_file_size: nil,
> has_funding_need: false, has_volunteer_need: false, is_visible: false,
> registration_documents: nil, delta: false, created_at: "2010-10-29
> 11:21:43", updated_at: "2010-10-29 11:21:43",
is_blacklisted: nil,
> is_complete_info: nil>, #<Ngo id: 11, user_id: 36, acronym_name: nil,
> service_id: nil, operation_start_date: nil, legal_structure: nil,
> other_legal_structure: nil, is_non_profit: nil, logo_file_name: nil,
> logo_content_type: nil, logo_file_size: nil, has_funding_need: false,
> has_volunteer_need: false, is_visible: false, registration_documents:
> nil, delta: false, created_at: "2010-10-29 11:26:02", updated_at:
> "2010-10-29 11:26:02", is_blacklisted: nil, is_complete_info:
nil>]
>
> Please help me.
> All suggestions accepted.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.