Hi,
I have a news item model that belongs to other 'newsable' models
polymorphicly and I want to index the 'organization_id' attribute of
this polymorphic association. When there's at least one news item for
each of the possible newsable-types in the news_items table,
configuring and indexing works all well. However, when the news_items
table is empty TS cannot determine the models that are associated as a
'newsable', and it seems it therefor treats 'organization_id' as it
where to be a column in the news_items table.
This is the model:
class NewsItem < ActiveRecord::Base
belongs_to :newsable, :polymorphic => true
define_index do
has newsable.organization_id, :as => :organization_id
end
end
When executing 'rake ts:conf' with some news items in the table
there's no problem, but when it's empty it says:
Cannot automatically map attribute organization_id in NewsItem to an
equivalent Sphinx type (integer, float, boolean, datetime, string as
ordinal).
You could try to explicitly convert the column's value in your
define_index
block:
has "CAST(column AS INT)", :type => :integer, :as => :column
I can get around this by adding the type option:
has newsable.organization_id, :as => :organization_id, :type
=> :integer
But if I then run 'rake ts:in' it says there were errors for the news
item index:
ERROR: index 'news_item_core': sql_range_query: Unknown column
'news_items.organization_id' in 'field list'
In production this might not be a very common scenario, but in
development mode it could be, and especially in test mode, when the
database is cleared before every test this poses a real problem.
Am I doing something wrong or what am I missing? Hope someone can help
me out.
Cheers,
Sjoerd
--
You received this message because you are subscribed to the Google Groups
"Thinking Sphinx" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/thinking-sphinx?hl=en.