开发者

Pony and Sequel associations conflict?

I've run into an issue when using Pony and Sequel in a Sinatra application. Without Pony everything goes just fine, but just requiring Pony sequel's associations break. Here's my models for a blog:

class Post < Sequel::Model

    one_to_many :comments, :order => :date.asc(), :conditions => {:approved => 1}

  set_schema do
    primary_key :id
    varchar :title
    varchar :text
    varchar :category
    varchar :status
    datetime :date
    varchar :link
  end
end

class Comment < Sequel::Model
    plugin :validation_helpers  
  many_to_one :posts
  attr_accessor :ip, :user_agent, :referrer, :permalink

  set_schema do
    primary_key 开发者_Python百科:id
    integer :post_id
    varchar :author
    varchar :comment
    DateTime :date
    varchar :email
    varchar :url
    varchar :approved
  end

Then I call them like this in a route

post '/:link' do
  @post = Post[:link=>params[:link]]
  params[:comment].merge!( {
        :ip         => request.ip.to_s,
        :user_agent => request.env['HTTP_USER_AGENT'].to_s,
        :referrer   => request.env['REFERER'].to_s,
        :permalink  => request.env['REFERER'].to_s
  } )
  begin
    @comment = Comment.create params[:comment]
    @post.add_comment @comment
  rescue
    @message = $!
  end
  @title = @post.title
  haml :posts
end

I don't even have to call pony somewhere, just requiring it @post.add_comment @comment fails. It says

NoMethodError - undefined method `_add_comments' for #<Post:0x102b09890>:
 /Library/Ruby/Gems/1.8/gems/sequel-3.21.0/lib/sequel/model/associations.rb:1078:in `send'
 /Library/Ruby/Gems/1.8/gems/sequel-3.21.0/lib/sequel/model/associations.rb:1078:in `add_associated_object'
 /Library/Ruby/Gems/1.8/gems/sequel-3.21.0/lib/sequel/model/associations.rb:743:in `add_comment'

Seems to me like a conflict with send? I don't even know how to start to debug it.


This is caused by an ActiveSupport issue, believe it or not. You should drop down to ActiveSupport 3.0.3 or manually require the default ActiveSupport inflections via:

require 'active_support/inflections'

Basically, after 3.0.3, ActiveSupport made it possible to load the inflector without the default inflections, which results in broken singularize and pluralize methods. The mail gem, which I'm guessing pony uses, is one of libraries that is known to be broken by this change.

The Rails developers apparently do not consider this a bug in ActiveSupport, but a bug in the libraries that use ActiveSupport.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜