
Search with using different unique indices
Reported by Marcel Ruegenberg | January 21st, 2009 @ 09:39 AM
If a table has no row named id, but instead a unique index (possibly over more than one row, see Rails' add_index), Searchlogic should still work.
Comments and changes to this ticket
-
Ben Johnson January 21st, 2009 @ 01:44 PM
- State changed from new to open
Ok, I need more details about how it doesn't work.
-
Ben Johnson January 22nd, 2009 @ 12:08 PM
I'm not sure what you mean by generating a model dynamically.
-
Ben Johnson January 22nd, 2009 @ 12:08 PM
I'm not sure what you mean by generating a model dynamically.
-
Ben Johnson January 23rd, 2009 @ 03:54 AM
If you can tell me how it depends on the id column I'll see if I can change that, but pagination shouldn't care about the id column.
-
Ben Johnson January 23rd, 2009 @ 04:34 AM
Yeah, it looks like it. The ultimate test is to see if you can execute that query without searchlogic, but just using ActiveRecord. If you get the same error then you know for sure its ActiveRecord.
-
Ben Johnson January 24th, 2009 @ 07:30 AM
Yeah, that doesn't really solve the issue, it just solves it for the count method. Let me see what I can do. What does your class return for primary_key ?
-
Ben Johnson January 26th, 2009 @ 12:53 PM
I should have commented my code there. Anyways, I'm pretty sure the * doesn't work with PostgreSQL if you are doing joins or includes. Otherwise I think it has to do with the other calculation functions that require a specific column to be specified, like avg().
-
Ben Johnson January 26th, 2009 @ 12:53 PM
If you can try this with PostgreSQL while using includes and confirm it works I'll make the change.
-
Ben Johnson January 26th, 2009 @ 03:52 PM
I found the issue, I tried to make the change and I get the following:
SQLite3::SQLException: near "*": syntax error: SELECT count(DISTINCT *) AS count_all FROM "users" LEFT OUTER JOIN "accounts" ON "accounts".id = "users".account_id
You can't use * with DISTINCT. I need to use this option, otherwise the calculations are not accurate with a left outer join, since that type of join returns duplicate results. So, by default, for a count operation, I need a column. Maybe I could just pick the first column returned by Model.column_names, since your model doesn't have a primary key.
-
jmrepetti (at gmail) January 26th, 2009 @ 06:49 PM
I don't know if this is the correct place but I have a problem related to composed keys.
I have a model, Cliente, I use composed keys(http://compositekeys.rubyforge.o...
class Cliente < ActiveRecord::Base #... set_primary_keys :clienteID, :nodo_codigo #... end
When I do the search:
@search = Cliente.new_search
@clientes = @search.all This work well, return all records. But this:
@clientes_count = @search.count ActiveRecord::StatementInvalid: Mysql::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'nodo_codigo) AS count_clienteid_nodo_codigo FROM
clientes
' at line 1: SELECT count(clienteID,nodo_codigo) AS count_clienteid_nodo_codigo FROMclientes
If I do:
@clientes_count = @search.count("clienteID AND nodo_codigo") => 4504
Works!, but in index.html.erb view, when I use 'page_select' helper I get this error again.
I do this, but is ugly, and not everyone always want :select. This work for me because I use MySQL and need a solution now
Searchlogic::ActiveRecord::Base def calculate_with_searchlogic(*args)
options = args.extract_options! options = filter_options_with_searchlogic(options, false) #------- if [primary_key].flatten.size > 1 options[:select] = primary_key.join(" AND ") end #------- args << options calculate_without_searchlogic(*args)
end end
I hope that this has been useful. Juan Matías
-
Ben Johnson January 27th, 2009 @ 04:50 AM
- State changed from open to resolved
This is all set, update from the repo. Let me know if you have any issues.
-
Ben Johnson January 27th, 2009 @ 04:51 AM
This should be fixed, update from the repo and let me know if you have any other issues.
-
Ben Johnson January 27th, 2009 @ 12:06 PM
Sorry, I pushed and didn't realize that. Should be good now.
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
Provides common named scopes and object based searching.