You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm working with an articles table that supports multiple article types (e.g., blog post, case study, knowledge base article). This table includes a column to track the number of times an article is viewed—an integer column that increments every time a show action is called for an article.
In implementing translations for these articles, I want to track the number of views for each translation individually, not for the main article object. In an effort to achieve this, I included the views property as one of the translated properties on my object:
I expect to receive an array of articles, as I did before implementing Mobility.
Actual Behavior
What I get instead is #<Article::ActiveRecord_Relation:0x233686c>. If I then try to convert that to an array with @top_articles.to_a, I get this error:
ArticleLoad(0.7ms)SELECT"articles".* FROM"articles"WHERE(posted_on < '2018-02-11')AND"articles"."type"IN('BlogPost','CaseStudy')ORDERBY"articles"."views"DESC,"articles"."posted_on"DESCLIMIT $1 [["LIMIT",10]]ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR: columnarticles.viewsdoes not existLINE1: ...les"."type" IN ('BlogPost', 'CaseStudy') ORDER BY "articles"... ^: SELECT "articles".* FROM "articles" WHERE (posted_on < '2018-02-11') AND "articles"."type" IN ('BlogPost', 'CaseStudy') ORDER BY "articles"."views" DESC, "articles"."posted_on" DESCLIMIT $1
from/usr/local/bundle/gems/activerecord-5.0.6/lib/active_record/connection_adapters/postgresql_adapter.rb:598:in `async_exec'
… returns #<#<Mobility::Backends::ActiveRecord::Table::QueryMethods:0x00000000050a86d8>:0x286c3e0>, and when I try to convert that to an array, I get the same thing:
ArticleLoad(0.7ms)SELECT"articles".* FROM"articles"WHERE(posted_on < '2018-02-11')AND"articles"."type"IN('BlogPost','CaseStudy')ORDERBY"articles"."views"DESC,"articles"."posted_on"DESCLIMIT $1 [["LIMIT",10]]ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR: columnarticles.viewsdoes not existLINE1: ...les"."type" IN ('BlogPost', 'CaseStudy') ORDER BY "articles"... ^: SELECT "articles".* FROM "articles" WHERE (posted_on < '2018-02-11') AND "articles"."type" IN ('BlogPost', 'CaseStudy') ORDER BY "articles"."views" DESC, "articles"."posted_on" DESCLIMIT $1
from/usr/local/bundle/gems/activerecord-5.0.6/lib/active_record/connection_adapters/postgresql_adapter.rb:598:in `async_exec'
I haven't tried ordering by any other translated field, so I don't know if it has something to do with the fact that this particular one is an integer (not a :string or :text type as shown in your documentation), or if Mobility only supports where clauses and not order clauses.
The text was updated successfully, but these errors were encountered:
Also, the type option is ignored for all backends other than the KeyValue backend. I think I need to change the readme to make this more obvious, many people seem to include it in their examples with other backends. In this case, type: :integer does absolutely nothing; the type of the column is determined by the actual column (i.e. article_translations.views, which I assume is an integer column).
Closing this, if you encounter any other issues please post to stackoverflow with the mobility tag, unless it seems to be an actual bug, in which case posting an issue is the right thing to do.
Context
I'm working with an articles table that supports multiple article types (e.g., blog post, case study, knowledge base article). This table includes a column to track the number of times an article is viewed—an integer column that increments every time a
show
action is called for an article.In implementing translations for these articles, I want to track the number of views for each translation individually, not for the main article object. In an effort to achieve this, I included the
views
property as one of the translated properties on my object:Expected Behavior
In my controller, I want to list the top ten most viewed articles, which I get with this query:
I expect to receive an array of articles, as I did before implementing Mobility.
Actual Behavior
What I get instead is
#<Article::ActiveRecord_Relation:0x233686c>
. If I then try to convert that to an array with@top_articles.to_a
, I get this error:Changing the query to include
i18n
:… returns
#<#<Mobility::Backends::ActiveRecord::Table::QueryMethods:0x00000000050a86d8>:0x286c3e0>
, and when I try to convert that to an array, I get the same thing:I haven't tried ordering by any other translated field, so I don't know if it has something to do with the fact that this particular one is an integer (not a
:string
or:text
type as shown in your documentation), or if Mobility only supportswhere
clauses and notorder
clauses.The text was updated successfully, but these errors were encountered: