Redmine trying to look for a "projects.id" in the activity stream

Added by César DJ Caësar 9114 about 4 years ago

I'm currently developping a redmine plugin, and I'd like to have the actions made with the plugin displayed in the activity stream and I'd also like to be able to search among the objects created by my plugin.
I followed Alex Bevilacque's tutorial, very carefully. If you have any clue on what I am doing wrong, it would be great!

Everything is about "prestations".

I've got this to migrate my db:

    class CreatePrestations < ActiveRecord::Migration
      def change
        create_table :prestations do |t|
          t.column :nom, :string, :null => false
          t.column :description, :text
          t.column :project_id, :int, :default => 0
          t.column :author_id, :int, :default => 0, :null => false
          t.timestamps
        end
      end
    end

And this model:

    class Prestation < ActiveRecord::Base
      belongs_to :project
      validates_presence_of :nom

      acts_as_searchable :columns => [ "#{table_name}.nom", "#{table_name}.description"],
                         :scope => preload(:project),
                         :date_column => "created_at" 

      acts_as_event :title => Proc.new { |o| "#{l(:label_title_prestation)} ##{o.id} - #{o.nom}"},
                    :description => :description,
                    :datetime => :updated_at,
                    :type => Proc.new { |o| 'prestation-' + (o.new_status ? 'add' : 'edit') },
                    :url => Proc.new { |o| {:controller => 'prestations', :action => 'show', :id => o.id, :project_id => o.project} }

      acts_as_activity_provider :scope => preload(:project),
                                :author_key => :author_id,
                                :type => 'prestations',
                                :timestamp => :updated_at,
                                :permission => :activity_presta

    end

And this at the very beginning of my init.rb:

    Rails.configuration.to_prepare do
      Redmine::Activity.register :prestations
      Redmine::Search.available_search_types << 'prestations'
    end

When I click on "search", I can search among every normal redmine fields, but not my "prestations", and when I look at the activity stream, I've got this:

    ActiveRecord::StatementInvalid (SQLite3::SQLException: no such column: projects.id: SELECT "prestations".* FROM "prestations" WHERE (updated_at BETWEEN '2016-05-20' AND '2016-06-19') AND (((projects.id = 1 OR (projects.lft > 1 AND projects.rgt < 2))) AND (projects.status = 1))):
      lib/plugins/acts_as_activity_provider/lib/acts_as_activity_provider.rb:81:in `find_events'
      lib/redmine/activity/fetcher.rb:91:in `block (2 levels) in events'
      lib/redmine/activity/fetcher.rb:90:in `each'
      lib/redmine/activity/fetcher.rb:90:in `block in events'
      lib/redmine/activity/fetcher.rb:89:in `each'
      lib/redmine/activity/fetcher.rb:89:in `events'
      app/controllers/activities_controller.rb:56:in `index'
      lib/redmine/sudo_mode.rb:63:in `sudo_mode'

I reseted the database to start a new redmine from scratch, I reloaded the server and changed the token, up to no avail.

I really don't understand why
1) I can't even get the possibility to search among my "prestations" (just having the checkbox would be great)
2) Rails tries to look for "projects.id" which I didn't ask for

Thanks a lot in advance.

Replies (3)

RE: Redmine trying to look for a "projects.id" in the activity stream - Added by César DJ Caësar 9114 about 4 years ago

I found something in projects.rb:

  def project_condition(with_subprojects)
    cond = "#{Project.table_name}.id = #{id}" 
    cond = "(#{cond} OR (#{Project.table_name}.lft > #{lft} AND #{Project.table_name}.rgt < #{rgt}))" if with_subprojects
    cond
  end

I think even though Redmine Knownledgebase tutorial is a good introduction, it's really full of bas examples if you want to make your own plugin.

RE: Redmine trying to look for a "projects.id" in the activity stream - Added by Alex Bevilacqua about 4 years ago

César Lizurey,

Glad you found a solution. Remember that the examples that were provided are dated now, and may not be 100% the same as what is required to write plugins for Redmine 3.0 and beyond.

RE: Redmine trying to look for a "projects.id" in the activity stream - Added by César DJ Caësar 9114 about 4 years ago

Exactly. Do you plan on writing another book?
It made me find the motivation to develop my own plugins, but when some things don't work it's a bit frustrating :)

(1-3/3)