rails - 活动管理员 - PG :: InvalidColumnReference:错误:SELECT DISTINCT ON表达式必须与初始ORDER BY表达式匹配

时间:2018-05-27 10:46:33

标签: ruby-on-rails activeadmin

我在模型中有一个范围,当我从rails控制台调用它时工作得很好但是当我尝试在活动管理中使用它时会抛出错误

这是范围

scope :clicked, -> { select('distinct on (email_stats.clicked_url) email_stats.*').order(:clicked_url, :action_performed_at)}

以下是我尝试在主动管理中使用它时出现的错误

  

ActionView :: Template :: Error(PG :: InvalidColumnReference:错误:SELECT DISTINCT ON表达式必须与初始ORDER BY表达式匹配   第1行:SELECT distinct(email_stats.clicked_url)email_stats。* ...                                ^   :SELECT distinct on(email_stats.clicked_url)email_stats。* FROM“email_stats”ORDER BY“email_stats”。“id”desc,“email_stats”。“clicked_url”ASC,“email_stats”。“action_performed_at”ASC LIMIT $ 1 OFFSET $ 2):

有谁可以让我知道我在这里缺少什么?我一直在寻找其他帖子,但似乎没有一个看起来有用。

1 个答案:

答案 0 :(得分:0)

尝试在范围内使用不同可能会有问题。相反,我使用:

 static void ConnectToSPO()
    {
        string SiteURL = "https://SPOSite.sharepoint.com/";

        #region Obtain token
        AuthenticationResult result = null;
        // first, try to get a token silently
        try
        {
            result = authContext.AcquireTokenSilentAsync(SiteURL, clientId).Result;
        }
        catch (AggregateException exc)
        {
            AdalException ex = exc.InnerException as AdalException;

            // There is no token in the cache; prompt the user to sign-in.
            if (ex != null && ex.ErrorCode != "failed_to_acquire_token_silently")
            {
                // An unexpected error occurred.
                ShowError(ex);
                return;
            }
        }

        if (result == null)
        {
            UserCredential uc = TextualPrompt();
            // if you want to use Windows integrated auth, comment the line above and uncomment the one below
            // UserCredential uc = new UserCredential();
            try
            {
                result = authContext.AcquireTokenAsync(todoListResourceId, clientId, uc).Result;
            }
            catch (Exception ee)
            {
                ShowError(ee);
                return;
            }
        }

        #endregion

        #region Get SharePoint Online Context & Access SPO Data

        using (ClientContext ctx = TokenHelper.GetClientContextWithAccessToken(SiteURL, result.AccessToken))
        {

            try
            {

                Console.ForegroundColor = ConsoleColor.Yellow;

                Console.WriteLine("");
                Console.WriteLine("*****************************************************************************");
                Console.WriteLine("Connecting To SPO Site: " + SiteURL);

                ctx.Load(ctx.Web);
                ctx.ExecuteQuery();
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Connected !");

                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("Info: Site Name-> " + ctx.Web.Title);

                ctx.Load(ctx.Web.CurrentUser);
                ctx.ExecuteQuery();
                Console.WriteLine("Info: Current User Login Name-> " + ctx.Web.CurrentUser.LoginName);

                #region Read List Items
                Console.WriteLine("");
                Console.WriteLine("Info: Reading list items from list Test List");

                List testlist = ctx.Web.Lists.GetByTitle("Test List");
                CamlQuery query = CamlQuery.CreateAllItemsQuery(100);
                ListItemCollection items = testlist.GetItems(query);
                ctx.Load(items);
                ctx.ExecuteQuery();
                foreach (ListItem listItem in items)
                {
                    // We have all the list item data. For example, Title. 
                    Console.WriteLine(listItem["Title"]);
                }

                Console.WriteLine("");
                #endregion
            }
            catch (Exception ex)
            {
                ShowError(ex);
            }
        } 
        #endregion
    }