Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined method error on edge rails #556

Closed
andriytyurnikov opened this issue May 26, 2014 · 12 comments
Closed

Undefined method error on edge rails #556

andriytyurnikov opened this issue May 26, 2014 · 12 comments

Comments

@andriytyurnikov
Copy link
Contributor

undefined method `primary' for #<ActiveRecord::ConnectionAdapters::PostgreSQLColumn:0x007fd398476620>
friendly_id (5.0.3) lib/friendly_id/base.rb:225:in `each'
friendly_id (5.0.3) lib/friendly_id/base.rb:225:in `find'
friendly_id (5.0.3) lib/friendly_id/base.rb:225:in `primary_key_type'

columns.find(&:primary).type

I can not find method primary in rails docs anyways

@parndt
Copy link
Collaborator

parndt commented May 26, 2014

Can you please give us more information like what steps you followed to get to this point?

@andriytyurnikov
Copy link
Contributor Author

@parndt well, sure, one second, but comment about find(&:primary) would be nice anyway)))

@andriytyurnikov
Copy link
Contributor Author

For associated model:

module MagazCore
  class Page < ActiveRecord::Base
    self.table_name = 'pages'
    extend FriendlyId
    belongs_to :shop

    friendly_id :handle, use: [:slugged, :scoped], scope: :shop

    validates :title,
      presence: true,
      uniqueness: { scope: :shop_id }

    def should_generate_new_friendly_id?
      handle_changed?
    end
  end
end

I invoke MagazCore::Shop.first.pages.friendly.find('non-existing-slug')
and get this exception

@parndt
Copy link
Collaborator

parndt commented May 26, 2014

I'm guessing it was a method that was around on non-edge Rails? It was introduced in fda8d3c

@andriytyurnikov
Copy link
Contributor Author

@parndt I've seen that commit, but I don't see primary as a method of ActiveRecord's column, even in rails 4.1.1

@parndt
Copy link
Collaborator

parndt commented May 26, 2014

@andriytyurnikov strange.
@jhdavids8 can you give us any help on this one please?

@jhdavids8
Copy link
Contributor

Hmm, perhaps they removed that method in edge? I don't have an edge Rails env setup at the moment, but another way to do it @andriytyurnikov is:

columns.find{ |c| c.name == primary_key}.type

If you can verify that works in your edge Rails env, perhaps we should change it to that. All we're trying to do there is find and cache the type of the column that is the primary key. Probably a few ways to do that, one of which was a 'primary' method that was true on the column that was the primary key.

@andriytyurnikov
Copy link
Contributor Author

@jhdavids8 , I'l give it a try, but again, primary method is absent in rails 4.1.1, not only edge, see api.rubyonrails.com
I am kinda surprised that this does not fail tests

@andriytyurnikov
Copy link
Contributor Author

@jhdavids8 , I've made monkeypatch with code, that you've offered - my tests green now, thanks!

@jhdavids8
Copy link
Contributor

Great! Do you want to submit the PR with that fix?

@andriytyurnikov
Copy link
Contributor Author

done ;)

@norman
Copy link
Owner

norman commented May 29, 2014

primary method is absent in rails 4.1.1

@andriytyurnikov I double checked this, and it's it's defined using attr_accessor :primary on 4.1 and lower. Will merge your fix for Edge Rails - thanks!

norman pushed a commit that referenced this issue May 29, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants