i need to index those association:
Author has_many :contributions
Author has_many :books, through: :contributions
I tried to write my index like:
ThinkingSphinx::Index.define :author, :with => :active_record do
indexes books(:title), as: :book
end
But it has no intention of working. any ideas?
EDIT
When i tried this, or pretty much every other solution i got this error after rake ts:index :
Generating configuration to /Users/Kuba/Desktop/Rails/black/config/development.sphinx.conf
rake aborted!
undefined method `active_record' for #<ActiveRecord::Associations::JoinDependency:0x007faa3d1e5070>
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/bundler/gems/thinking-sphinx-ec658bff0479/lib/thinking_sphinx/active_record/associations.rb:78:in `reflection_for'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/bundler/gems/thinking-sphinx-ec658bff0479/lib/thinking_sphinx/active_record/associations.rb:50:in `join_for'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/bundler/gems/thinking-sphinx-ec658bff0479/lib/thinking_sphinx/active_record/associations.rb:38:in `model_for'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/bundler/gems/thinking-sphinx-ec658bff0479/lib/thinking_sphinx/active_record/property_sql_presenter.rb:42:in `column_exists?'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/bundler/gems/thinking-sphinx-ec658bff0479/lib/thinking_sphinx/active_record/property_sql_presenter.rb:48:in `column_with_table'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/bundler/gems/thinking-sphinx-ec658bff0479/lib/thinking_sphinx/active_record/property_sql_presenter.rb:55:in `block in columns_with_table'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/bundler/gems/thinking-sphinx-ec658bff0479/lib/thinking_sphinx/active_record/property_sql_presenter.rb:54:in `collect'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/bundler/gems/thinking-sphinx-ec658bff0479/lib/thinking_sphinx/active_record/property_sql_presenter.rb:54:in `columns_with_table'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/bundler/gems/thinking-sphinx-ec658bff0479/lib/thinking_sphinx/active_record/property_sql_presenter.rb:31:in `casted_column_with_table'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/bundler/gems/thinking-sphinx-ec658bff0479/lib/thinking_sphinx/active_record/property_sql_presenter.rb:15:in `to_select'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/bundler/gems/thinking-sphinx-ec658bff0479/lib/thinking_sphinx/active_record/sql_builder.rb:127:in `collect'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/bundler/gems/thinking-sphinx-ec658bff0479/lib/thinking_sphinx/active_record/sql_builder.rb:127:in `select_clause'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/bundler/gems/thinking-sphinx-ec658bff0479/lib/thinking_sphinx/active_record/sql_builder.rb:10:in `sql_query'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/bundler/gems/thinking-sphinx-ec658bff0479/lib/thinking_sphinx/active_record/sql_source.rb:120:in `prepare_for_render'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/bundler/gems/thinking-sphinx-ec658bff0479/lib/thinking_sphinx/active_record/sql_source.rb:62:in `render'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/gems/riddle-1.5.8/lib/riddle/configuration/index.rb:29:in `block in render'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/gems/riddle-1.5.8/lib/riddle/configuration/index.rb:29:in `collect'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/gems/riddle-1.5.8/lib/riddle/configuration/index.rb:29:in `render'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/bundler/gems/thinking-sphinx-ec658bff0479/lib/thinking_sphinx/core/index.rb:53:in `render'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/gems/riddle-1.5.8/lib/riddle/configuration.rb:39:in `block in render'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/gems/riddle-1.5.8/lib/riddle/configuration.rb:39:in `collect'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/gems/riddle-1.5.8/lib/riddle/configuration.rb:39:in `render'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/bundler/gems/thinking-sphinx-ec658bff0479/lib/thinking_sphinx/configuration.rb:78:in `render'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/bundler/gems/thinking-sphinx-ec658bff0479/lib/thinking_sphinx/configuration.rb:84:in `block in render_to_file'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/bundler/gems/thinking-sphinx-ec658bff0479/lib/thinking_sphinx/configuration.rb:84:in `render_to_file'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/bundler/gems/thinking-sphinx-ec658bff0479/lib/thinking_sphinx/rake_interface.rb:4:in `configure'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/bundler/gems/thinking-sphinx-ec658bff0479/lib/thinking_sphinx/rake_interface.rb:31:in `index'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/bundler/gems/thinking-sphinx-ec658bff0479/lib/thinking_sphinx/tasks.rb:9:in `block (2 levels) in <top (required)>'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/bin/ruby_noexec_wrapper:14:in `eval'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => ts:index
(See full trace by running task with --trace)
Try this,
ThinkingSphinx::Index.define :author, :with => :active_record do
indexes books.title, :as => :title
end
Edit:
Please check this issue in the git. https://github.com/pat/thinking-sphinx/issues/517
Related
I am using Rails 3.2.14, thinking-sphinx 3.1.1 and Sphinx 2.2.4-id64-release (r4806)
I have two modals below:-
Album.rb
has_and_belongs_to_many :genres
Genre.rb
has_and_belongs_to_many :albums
So the associated table is albums_genres
I want to search albums using the genre_id
Example: When I pass a genre_id then it should return all the albums associated to that genre_id on the basis of third table albums_genres
I have tried like that
ThinkingSphinx::Index.define :album, :with => :active_record do
#other indexes
has genres.id, :as => :genre_ids, :source => :query
end
But when i run the rake task as rake ts:index i am getting the error as:-
rake aborted!
undefined method `join_table' for #<ActiveRecord::Reflection::AssociationReflection:0x000000079224d8>
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/simple_many_query.rb:15:in `quoted_foreign_key'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/simple_many_query.rb:28:in `to_sql'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/property_query.rb:76:in `queries'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/simple_many_query.rb:5:in `to_s'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/property_query.rb:15:in `to_s'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/attribute/sphinx_presenter.rb:45:in `query'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/attribute/sphinx_presenter.rb:38:in `multi_declaration'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/attribute/sphinx_presenter.rb:23:in `declaration'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/sql_source.rb:96:in `block in append_presenter_to_attribute_array'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/sql_source.rb:93:in `each'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/sql_source.rb:93:in `append_presenter_to_attribute_array'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/sql_source.rb:132:in `prepare_for_render'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/sql_source.rb:65:in `render'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/riddle-1.5.11/lib/riddle/configuration/index.rb:29:in `block in render'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/riddle-1.5.11/lib/riddle/configuration/index.rb:29:in `collect'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/riddle-1.5.11/lib/riddle/configuration/index.rb:29:in `render'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/core/index.rb:53:in `render'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/riddle-1.5.11/lib/riddle/configuration.rb:43:in `block in render'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/riddle-1.5.11/lib/riddle/configuration.rb:43:in `collect'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/riddle-1.5.11/lib/riddle/configuration.rb:43:in `render'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/configuration.rb:90:in `render'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/configuration.rb:96:in `block in render_to_file'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/configuration.rb:96:in `render_to_file'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/rake_interface.rb:13:in `configure'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/rake_interface.rb:24:in `index'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/tasks.rb:9:in `block (2 levels) in <top (required)>'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/bin/ruby_executable_hooks:15:in `eval'
/home/shamsul/.rvm/gems/ruby-1.9.3-p392/bin/ruby_executable_hooks:15:in `<main>'
It looks like this is a bug with Rails 3.2, :source => :query and HABTM joins (which is sadly not surprising - getting the code to work even with Rails 4.0 was painful and fragile).
I'm afraid your options are either upgrade to Rails 4 or not use the :source => :query option (and I know that means you lose some nice speed gains for indexing).
Odds of me getting a patch sorted in the near future is small (but others are welcome to give it a shot, if they wish).
I'm not new to DynamoDB, but I'm new to DynamoID gem.
I can't achieve to make it work since I get the following error :
/aws-sdk-1.28.1/lib/aws/core/client.rb:366:in `return_or_raise': The action or operation requested is invalid. Verify that the action is typed correctly. (AWS::DynamoDB::Errors::InvalidAction)
/aws-sdk-1.28.1/lib/aws/core/client.rb:467:in `client_request'
(eval):3:in `list_tables'
/aws-sdk-1.28.1/lib/aws/dynamo_db/table_collection.rb:121:in `_each_item'
/aws-sdk-1.28.1/lib/aws/core/collection/with_limit_and_next_token.rb:54:in `_each_batch'
/aws-sdk-1.28.1/lib/aws/core/collection.rb:80:in `each_batch'
/aws-sdk-1.28.1/lib/aws/core/collection.rb:47:in `each'
/dynamoid-0.7.1/lib/dynamoid/adapter/aws_sdk.rb:185:in `collect'
/dynamoid-0.7.1/lib/dynamoid/adapter/aws_sdk.rb:185:in `list_tables'
/dynamoid-0.7.1/lib/dynamoid/adapter.rb:146:in `block (3 levels) in <module:Adapter>'
/dynamoid-0.7.1/lib/dynamoid/adapter.rb:39:in `benchmark'
/dynamoid-0.7.1/lib/dynamoid/adapter.rb:146:in `block (2 levels) in <module:Adapter>'
/dynamoid-0.7.1/lib/dynamoid/adapter.rb:25:in `block in reconnect!'
/dynamoid-0.7.1/lib/dynamoid/adapter.rb:39:in `benchmark'
/dynamoid-0.7.1/lib/dynamoid/adapter.rb:25:in `reconnect!'
/dynamoid-0.7.1/lib/dynamoid.rb:35:in `configure'
app/config/initializers/dynamoid.rb:1:in `<top (required)>'
It seems that list_tables doesn't exist, but it's a method of the AWS Ruby SDK
My model is very simple :
class Interaction
include Dynamoid::Document
table :name => :interactions, :key => :from, :read_capacity => 1, :write_capacity => 1
end
Could anybody help?
Cheers,
Emmanuel
I have installed thinking sphinx and after running rake ts:index , it fails to configure the development file. The file is created, but it is empty.
Generating configuration to /Users/lexi87/dating/config/development.sphinx.conf
rake aborted!
undefined method `type' for nil:NilClass
/Users/lexi87/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.0/lib/thinking_sphinx/active_record/attribute/type.rb:64:in `type_from_database'
/Users/lexi87/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.0/lib/thinking_sphinx/active_record/attribute/type.rb:17:in `type'
/Users/lexi87/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.0/lib/thinking_sphinx/active_record/attribute.rb:4:in `type'
/Users/lexi87/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.0/lib/thinking_sphinx/active_record/attribute/sphinx_presenter.rb:30:in `sphinx_type'
/Users/lexi87/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.0/lib/thinking_sphinx/active_record/attribute/sphinx_presenter.rb:18:in `collection_type'
/Users/lexi87/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.0/lib/thinking_sphinx/active_record/sql_source.rb:107:in `block in prepare_for_render'
/Users/lexi87/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.0/lib/thinking_sphinx/active_record/sql_source.rb:104:in `each'
/Users/lexi87/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.0/lib/thinking_sphinx/active_record/sql_source.rb:104:in `prepare_for_render'
/Users/lexi87/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.0/lib/thinking_sphinx/active_record/sql_source.rb:61:in `render'
/Users/lexi87/.rvm/gems/ruby-2.0.0-p0/gems/riddle-1.5.6/lib/riddle/configuration/index.rb:29:in `block in render'
/Users/lexi87/.rvm/gems/ruby-2.0.0-p0/gems/riddle-1.5.6/lib/riddle/configuration/index.rb:29:in `collect'
/Users/lexi87/.rvm/gems/ruby-2.0.0-p0/gems/riddle-1.5.6/lib/riddle/configuration/index.rb:29:in `render'
/Users/lexi87/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.0/lib/thinking_sphinx/core/index.rb:48:in `render'
/Users/lexi87/.rvm/gems/ruby-2.0.0-p0/gems/riddle-1.5.6/lib/riddle/configuration.rb:39:in `block in render'
/Users/lexi87/.rvm/gems/ruby-2.0.0-p0/gems/riddle-1.5.6/lib/riddle/configuration.rb:39:in `collect'
/Users/lexi87/.rvm/gems/ruby-2.0.0-p0/gems/riddle-1.5.6/lib/riddle/configuration.rb:39:in `render'
/Users/lexi87/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.0/lib/thinking_sphinx/configuration.rb:81:in `render'
/Users/lexi87/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.0/lib/thinking_sphinx/configuration.rb:87:in `block in render_to_file'
/Users/lexi87/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.0/lib/thinking_sphinx/configuration.rb:87:in `render_to_file'
/Users/lexi87/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.0/lib/thinking_sphinx/rake_interface.rb:4:in `configure'
/Users/lexi87/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.0/lib/thinking_sphinx/rake_interface.rb:31:in `index'
/Users/lexi87/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.0/lib/thinking_sphinx/tasks.rb:9:in `block (2 levels) in <top (required)>'
/Users/lexi87/.rvm/gems/ruby-2.0.0-p0/bin/ruby_noexec_wrapper:14:in `eval'
/Users/lexi87/.rvm/gems/ruby-2.0.0-p0/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => ts:index
I am not sure if this is related to my user_index.rb under the indices folder.
ThinkingSphinx::Index.define :user, :with => :active_record do
# fields
indexes content
indexes user.name, :as => :user, :sortable => true
# attributes
has user_id, created_at, updated_at, ethnicity, religion
end
Here's my thinking_sphinx.yml file:
development:
mysql41: 9312
test:
mysql41: 9313
production:
mysql41: 9312
Any help would be greatly appreciated.
This error, while not clear, is due to one of your attribute references being not quite correct... If you're indexing the User model, then I'm guessing there isn't an association on it called user - so, user_id should just be id, and user.name should just be name:
ThinkingSphinx::Index.define :user, :with => :active_record do
# fields
indexes content
indexes name, :as => :user, :sortable => true
# attributes
has id, created_at, updated_at, ethnicity, religion
end
There are two model classes in my project. The first is User:
class User < ActiveRecord::Base
attr_accessible :email, :name
has_many :micropost1s
end
The other is Micropost1
class Micropost1 < ActiveRecord::Base
attr_accessible :content, :user_id
belongs_to :user
validates :content, :length => { :maximum => 140 }
end
I am not getting where I am wrong. First I run this command for assigning variable first_user:
first_user = User.first
After that I write in console:
first_user.micropost1s
I am getting this error log:
Micropost1 Load (0.3ms) SELECT "micropost1s".* FROM "micropost1s" WHERE "micropost1s"."user_id" = 1
SQLite3::SQLException: no such column: micropost1s.user_id: SELECT "micropost1s".* FROM "micropost1s" WHERE "micropost1s"."user_id" = 1
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: micropost1s.user_id: SELECT "micropost1s".* FROM "micropost1s" WHERE "micropost1s"."user_id" = 1
from /var/lib/gems/1.8/gems/sqlite3-1.3.5/lib/sqlite3/database.rb:91:in `initialize'
from /var/lib/gems/1.8/gems/sqlite3-1.3.5/lib/sqlite3/database.rb:91:in `new'
from /var/lib/gems/1.8/gems/sqlite3-1.3.5/lib/sqlite3/database.rb:91:in `prepare'
from /var/lib/gems/1.8/gems/activerecord-3.2.9/lib/active_record/connection_adapters/sqlite_adapter.rb:246:in `exec_query'
from /var/lib/gems/1.8/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `log'
from /var/lib/gems/1.8/gems/activesupport-3.2.9/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
from /var/lib/gems/1.8/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
from /var/lib/gems/1.8/gems/activerecord-3.2.9/lib/active_record/connection_adapters/sqlite_adapter.rb:242:in `exec_query'
from /var/lib/gems/1.8/gems/activerecord-3.2.9/lib/active_record/connection_adapters/sqlite_adapter.rb:467:in `select'
from /var/lib/gems/1.8/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/database_statements.rb:18:in `select_all'
from /var/lib/gems/1.8/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/query_cache.rb:63:in `select_all'
from /var/lib/gems/1.8/gems/activerecord-3.2.9/lib/active_record/querying.rb:38:in `find_by_sql'
from /var/lib/gems/1.8/gems/activerecord-3.2.9/lib/active_record/explain.rb:40:in `logging_query_plan'
from /var/lib/gems/1.8/gems/activerecord-3.2.9/lib/active_record/querying.rb:37:in `find_by_sql'
from /var/lib/gems/1.8/gems/activerecord-3.2.9/lib/active_record/relation.rb:171:in `exec_queries'
from /var/lib/gems/1.8/gems/activerecord-3.2.9/lib/active_record/relation.rb:160:in `to_a'
... 5 levels...
from /var/lib/gems/1.8/gems/activerecord-3.2.9/lib/active_record/associations/collection_proxy.rb:44:in `__send__'
from /var/lib/gems/1.8/gems/activerecord-3.2.9/lib/active_record/associations/collection_proxy.rb:44:in `load_target'
from /var/lib/gems/1.8/gems/activerecord-3.2.9/lib/active_record/associations/collection_proxy.rb:87:in `method_missing'
from /usr/lib/ruby/1.8/irb.rb:310:in `output_value'
from /usr/lib/ruby/1.8/irb.rb:159:in `eval_input'
from /usr/lib/ruby/1.8/irb.rb:271:in `signal_status'
from /usr/lib/ruby/1.8/irb.rb:155:in `eval_input'
from /usr/lib/ruby/1.8/irb.rb:154:in `eval_input'
from /usr/lib/ruby/1.8/irb.rb:71:in `start'
from /usr/lib/ruby/1.8/irb.rb:70:in `catch'
from /usr/lib/ruby/1.8/irb.rb:70:in `start'
from /var/lib/gems/1.8/gems/railties-3.2.9/lib/rails/commands/console.rb:47:in `start'
from /var/lib/gems/1.8/gems/railties-3.2.9/lib/rails/commands/console.rb:8:in `start'
from /var/lib/gems/1.8/gems/railties-3.2.9/lib/rails/commands.rb:41
from script/rails:6:in `require'
from script/rails:6irb(main):008:0>
Sounds like you haven't run the migrations generated by creating your models:
$ rake db:migrate
If this doesn't work, you may need to add a user_id column to your Micropost1 model. E.g:
$ rails g migration add_user_id_to_micropost1s
Then edit the generated migration to create the field as desired. Alternatively you could re-create the model with a reference to a user:
$ rails g model Micropost1 something:string user:references
I want to build a simple favorite system. I've found tutorial for polymorphic associations on the web but i'm sure there is a lot more simple !!
So I have a User model and I want to let users have has many other users as favorites.
In the other way, a user may know who favored him.
I tried something like this:
class User < ActiveRecord::Base
has_many :favorites, :class_name => 'User', :foreign_key => 'user_id'
belongs_to :favorited_by, :class_name => 'User'
end
But I have an SQL error while doing
some_user.favorites << another_user
or
some_user.favorites.build(another_user)
some_user.save
some_user.favorites
Any help doing this simple thing... :)
Here is the trace:
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: users.user_id: SELECT "users".* FROM "users" WHERE ("users".user_id = 1)
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.9/lib/active_record/connection_adapters/abstract_adapter.rb:207:in `rescue in log'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.9/lib/active_record/connection_adapters/abstract_adapter.rb:199:in `log'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.9/lib/active_record/connection_adapters/sqlite_adapter.rb:135:in `execute'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.9/lib/active_record/connection_adapters/sqlite_adapter.rb:284:in `select'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.9/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `select_all'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.9/lib/active_record/connection_adapters/abstract/query_cache.rb:56:in `select_all'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.9/lib/active_record/base.rb:473:in `find_by_sql'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.9/lib/active_record/relation.rb:64:in `to_a'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.9/lib/active_record/relation/finder_methods.rb:143:in `all'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.9/lib/active_record/associations/association_collection.rb:70:in `block in find'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.9/lib/active_record/base.rb:1127:in `with_scope'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.9/lib/active_record/associations/association_proxy.rb:207:in `with_scope'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.9/lib/active_record/associations/association_collection.rb:63:in `find'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.9/lib/active_record/associations/association_collection.rb:468:in `find_target'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.9/lib/active_record/associations/association_collection.rb:398:in `load_target'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.9/lib/active_record/associations/association_proxy.rb:145:in `inspect'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/commands/console.rb:44:in `start'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/commands/console.rb:8:in `start'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/commands.rb:23:in `<top (required)>'
from script/rails:6:in `require'
Answering my own thx to #Dogbert
Your model associations are wrong. Have a look at my answer here and adapt it for your use case.