Hobo 2.0.1 - Converting a :conditions parameter to a scope blocks - wrong number of arguments.

79 views
Skip to first unread message

Tim Griffin

unread,
Jan 28, 2014, 3:39:25 PM1/28/14
to hobo...@googlegroups.com

Hi all;

In updating my app to Hobo 2.0.1, I'm having to make some changes as advised by Rails 4. 

One that's tripping up Hobo 2.0.1 is converting a :conditions parameter on a belongs_to to be a scope block.

In a Title model, that means this:
  belongs_to  :condo_holding_title, :class_name => "Title", :foreign_key => :condominium_holding_title, :conditions => "title_type = 'CondominiumHolding'"

Needs to become this:
  belongs_to  :condo_holding_title, -> { where("title_type = 'CondominiumHolding'") }, :class_name => "Title", :foreign_key => :condominium_holding_title

But the revised version is throwing:

/Users/tgriffin/.rvm/gems/ruby-1.9.3-p374/gems/hobo_fields-2.1.0/lib/hobo_fields/model.rb:86:in `belongs_to_with_field_declarations': wrong number of arguments (3 for 2) (ArgumentError)

As far as I can see, that method is declared with 3 arguments:

    def self.belongs_to_with_field_declarations(name, options={}, &block)

Why is it expecting 2? 

Tim

Tim Griffin

unread,
Jan 28, 2014, 3:41:46 PM1/28/14
to hobo...@googlegroups.com
I forgot to mention that this is being done from a non-Rails Ruby application (i.e. just using hobo_fields, hobo_support, activerecord, etc.)

T

Tim Griffin

unread,
Jan 28, 2014, 3:45:33 PM1/28/14
to hobo...@googlegroups.com

The Title model I'm using below is not designated as a "hobo_model". 

So, I think my experience is being skewed here. 

Let's ignore this issue since it's not within a Rails app.

Sorry!

Tim

kevinpfromnm

unread,
Jan 29, 2014, 12:29:47 PM1/29/14
to hobo...@googlegroups.com
Did you have a copy/paste issue there? -> doesn't match any ruby syntax I know of.  I would think you'd want something like :keyname => ... in it's place.

Tim Griffin

unread,
Jan 29, 2014, 12:35:57 PM1/29/14
to hobo...@googlegroups.com
Hey Kevin;

Nope, that syntax comes straight from the RailsGuides:


See specifically section 4.3.3.1:

4.3.3.1 where

The where method lets you specify the conditions that the associated object must meet.

class Customer < ActiveRecord::Base
  has_many :confirmed_orders, -> { where "confirmed = 1" },
    class_name: "Order"
end

Tim



--
You received this message because you are subscribed to a topic in the Google Groups "Hobo Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/hobousers/LFPHsqTg8p0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to hobousers+...@googlegroups.com.
To post to this group, send email to hobo...@googlegroups.com.
Visit this group at http://groups.google.com/group/hobousers.
For more options, visit https://groups.google.com/groups/opt_out.

Tim Griffin

unread,
Jan 29, 2014, 12:39:31 PM1/29/14
to hobo...@googlegroups.com
Sorry, I meant the section on conditions on a belongs_to:
4.1.3 Scopes for belongs_to

There may be times when you wish to customize the query used by belongs_to. Such customizations can be achieved via a scope block. For example:

class Order < ActiveRecord::Base
  belongs_to :customer, -> { where active: true },
                        dependent: :destroy
end


​Still, I think my bigger problem is operating with Hobo outside of the warm blanket of Rails.

T​

Owen Dall

unread,
Jan 29, 2014, 1:22:28 PM1/29/14
to Hobo Users
BTW, Hobo 2.0.1 has only been officially been tested with Rails 3.x, not Rails 4. 

Hobo 2.1 (TBA) is being tested with Rails 4 by Ignacio.






-Owen


Owen Dall

Vice President | Chief Technology Officer

Barquin International

Office: 202.296.7147 | Mobile: 410.991.0811

Fax: 202.296.8903 | email: od...@barquin.com

BI_Logo_2012_JPEG

 

NOTICE: If you have received this message in error, please contact the sender immediately and be aware that the use, copying, or dissemination of this information is prohibited. This email transmission contains information from Barquin International that may be considered privileged or confidential and is intended solely for the named recipient.










--
You received this message because you are subscribed to the Google Groups "Hobo Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hobousers+...@googlegroups.com.
image001.jpg

Tim Griffin

unread,
Jan 29, 2014, 1:29:20 PM1/29/14
to hobo...@googlegroups.com
Whoops, Owen, thanks for finding my typo "2.0.1". 

But, I've been upgrading my app to Hobo 2.1.0, not 2.0.1, and working against:

gem 'activerecord', '~> 4.0.2'
gem 'activesupport', '~> 4.0.2'
gem 'rake', '0.9.2.2'
gem 'tiny_tds'
gem 'activerecord-sqlserver-adapter', :git => 'https://github.com/rails-sqlserver/activerecord-sqlserver-adapter.git', :branch => 'master'
gem 'hobo_support', '2.1.0'   
gem 'hobo_fields', '2.1.0'
gem 'pg', '0.17.1'
gem 'activerecord-postgresql-adapter', '~> 0.0.1'

Tim



--
You received this message because you are subscribed to a topic in the Google Groups "Hobo Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/hobousers/LFPHsqTg8p0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to hobousers+...@googlegroups.com.
image001.jpg

Owen Dall

unread,
Jan 29, 2014, 1:47:37 PM1/29/14
to Hobo Users
Ah. OK.  
image001.jpg

Ignacio Huerta

unread,
Jan 29, 2014, 2:21:03 PM1/29/14
to hobo...@googlegroups.com
Oh no, the "wrong_number_or_arguments (3 for 2)" error. I have seen that
before, while migrating Hobo to Rails 4. I fixed that for the
accessible_associations, but I think this new belongs_to syntax escaped
the testing.

If you take a look at line 106:
https://github.com/Hobo/hobo/commit/473689db2f9ea9251d9b15bc95de038e7dddb967#diff-81a582d9922cd6b5919ee9ae1f508138R106

You'll see the "hack" I implemented. This syntax is very weird, because
you can get the options hash as the second or the third argument. If you
ask why "3 for 2", it's because the "&block" is not counted, at least to
my knowledge.

Short answer: You've found a bug!

Workaround: Try using the old ":conditions" syntax, or setting a default
scope in the model.

Solution: I think we need to implement the same hack in hobo_fields.
I'll open a bug and try to reproduce when I have some time. Please say
if this is a blocking bug so I can priorize.

Warm regards,
Ignacio


El 29/01/14 18:35, Tim Griffin escribió:
> Hey Kevin;
>
> Nope, that syntax comes straight from the RailsGuides:
>
> http://guides.rubyonrails.org/association_basics.html#scopes-for-has-many-order
>
> See specifically section 4.3.3.1 <http://4.3.3.1>:
>
>
> 4.3.3.1 |where|
>
> The |where| method lets you specify the conditions that the associated
> object must meet.
>
> |class| |Customer < ActiveRecord::Base|
> | ||has_many ||:confirmed_orders||, -> { where ||"confirmed = 1"| |},|
> | ||class_name: ||"Order"|
> |end|
>
>
> Tim
>
>
>
> On Wed, Jan 29, 2014 at 12:29 PM, kevinpfromnm <kevinp...@gmail.com
> <mailto:kevinp...@gmail.com>> wrote:
>
> Did you have a copy/paste issue there? -> doesn't match any ruby
> syntax I know of. I would think you'd want something like :keyname
> => ... in it's place.
>
>
> On Tuesday, January 28, 2014 1:39:25 PM UTC-7, Tim Griffin wrote:
>
>
> Hi all;
>
> In updating my app to Hobo 2.0.1, I'm having to make some
> changes as advised by Rails 4.
>
> One that's tripping up Hobo 2.0.1 is converting a :conditions
> parameter on a belongs_to to be a scope block.
>
> In a Title model, that means this:
> belongs_to :condo_holding_title, :class_name => "Title",
> :foreign_key => :condominium_holding_title, :conditions =>
> "title_type = 'CondominiumHolding'"
>
> Needs to become this:
> belongs_to :condo_holding_title, -> { where("title_type =
> 'CondominiumHolding'") }, :class_name => "Title", :foreign_key
> => :condominium_holding_title
>
> But the revised version is throwing:
>
> /Users/tgriffin/.rvm/gems/__ruby-1.9.3-p374/gems/hobo___fields-2.1.0/lib/hobo_fields/__model.rb:86:in
> `belongs_to_with_field___declarations': wrong number of
> arguments (3 for 2) (ArgumentError)
>
> As far as I can see, that method is declared with 3 arguments:
>
> def self.belongs_to_with_field___declarations(name,
> options={}, &block)
>
> Why is it expecting 2?
>
> Tim
>
> --
> You received this message because you are subscribed to a topic in
> the Google Groups "Hobo Users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/hobousers/LFPHsqTg8p0/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> hobousers+...@googlegroups.com
> <mailto:hobousers%2Bunsu...@googlegroups.com>.
> To post to this group, send email to hobo...@googlegroups.com
> <mailto:hobo...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/hobousers.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Hobo Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to hobousers+...@googlegroups.com.
> To post to this group, send email to hobo...@googlegroups.com.
> Visit this group at http://groups.google.com/group/hobousers.
> For more options, visit https://groups.google.com/groups/opt_out.

--
Ignacio Huerta Arteche
http://www.ihuerta.net
Teléfono: 0034 645 70 77 35
Email realizado con software libre

Ignacio Huerta

unread,
Jan 29, 2014, 2:24:29 PM1/29/14
to hobo...@googlegroups.com
Funny thing, I had misread "2.1.0" instead of "2.0.1" from the start and
my answer went along those lines :P.

This is the bug: https://github.com/Hobo/hobo/issues/66

Please say if it's urgent ;).

Regards,
Ignacio

El 29/01/14 19:47, Owen Dall escribió:
> Ah. OK.
>
> */
> /*
>
> */
> /*
>
> */
> /*
>
> */-Owen/*
>
> */
> /*
>
> *Owen Dall*
>
> *Vice President | Chief Technology Officer*
>
> *Barquin International*
>
> *Office: 202.296.7147 | Mobile: 410.991.0811*
>
> *Fax: 202.296.8903 | email:** od...@barquin.com <mailto:od...@barquin.com>*
>
> BI_Logo_2012_JPEG
>
>
>
> NOTICE: If you have received this message in error, please contact the
> sender immediately and be aware that the use, copying, or dissemination
> of this information is prohibited. This email transmission contains
> information from Barquin International that may be considered privileged
> or confidential and is intended solely for the named recipient.
>
>
>
>
>
>
>
>
>
>
> On Wed, Jan 29, 2014 at 1:29 PM, Tim Griffin <tim.g...@enwood.ca
> <mailto:tim.g...@enwood.ca>> wrote:
>
> Whoops, Owen, thanks for finding my typo "2.0.1".
>
> But, I've been upgrading my app to *Hobo 2.1.0*, not 2.0.1, and
> working against:
>
> gem 'activerecord', '~> 4.0.2'
> gem 'activesupport', '~> 4.0.2'
> gem 'rake', '0.9.2.2'
> gem 'tiny_tds'
> gem 'activerecord-sqlserver-adapter', :git =>
> 'https://github.com/rails-sqlserver/activerecord-sqlserver-adapter.git',
> :branch => 'master'
> gem 'hobo_support', '2.1.0'
> gem 'hobo_fields', '2.1.0'
> gem 'pg', '0.17.1'
> gem 'activerecord-postgresql-adapter', '~> 0.0.1'
>
> Tim
>
>
>
> On Wed, Jan 29, 2014 at 1:22 PM, Owen Dall <od...@barquin.com
> <mailto:od...@barquin.com>> wrote:
>
> BTW, Hobo 2.0.1 has only been officially been tested with Rails
> 3.x, not Rails 4.
>
> Hobo 2.1 (TBA) is being tested with Rails 4 by Ignacio.
>
>
>
> */
> /*
>
> */
> /*
>
> */
> /*
>
> */-Owen/*
>
> */
> /*
>
> *Owen Dall*
>
> *Vice President | Chief Technology Officer*
>
> *Barquin International*
>
> *Office: 202.296.7147 | Mobile: 410.991.0811*
>
> *Fax: 202.296.8903 | email:** od...@barquin.com
> <mailto:od...@barquin.com>*
>
> BI_Logo_2012_JPEG
>
>
>
> NOTICE: If you have received this message in error, please
> contact the sender immediately and be aware that the use,
> copying, or dissemination of this information is prohibited.
> This email transmission contains information from Barquin
> International that may be considered privileged or confidential
> and is intended solely for the named recipient.
>
>
>
>
>
>
>
>
>
>
> <mailto:hobousers%2Bunsu...@googlegroups.com>.
>
> To post to this group, send email to
> hobo...@googlegroups.com <mailto:hobo...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/hobousers.
> For more options, visit
> https://groups.google.com/groups/opt_out.
>
>
> --
> You received this message because you are subscribed to a topic
> in the Google Groups "Hobo Users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/hobousers/LFPHsqTg8p0/unsubscribe.
> To unsubscribe from this group and all its topics, send an email
> to hobousers+...@googlegroups.com
> <mailto:hobousers%2Bunsu...@googlegroups.com>.
>
> To post to this group, send email to hobo...@googlegroups.com
> <mailto:hobo...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/hobousers.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Hobo Users" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to hobousers+...@googlegroups.com
> <mailto:hobousers%2Bunsu...@googlegroups.com>.
> To post to this group, send email to hobo...@googlegroups.com
> <mailto:hobo...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/hobousers.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Hobo Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to hobousers+...@googlegroups.com.
> To post to this group, send email to hobo...@googlegroups.com.
> Visit this group at http://groups.google.com/group/hobousers.
> For more options, visit https://groups.google.com/groups/opt_out.

Tim Griffin

unread,
Jan 29, 2014, 2:32:59 PM1/29/14
to hobo...@googlegroups.com
Ah, thanks Ignacio.

Well, at least your hack is a very readable hack! Sorry to have found a bug. I know it's a good thing, but....

This is not a blocking bug for me... I made the change just to silence the deprecation warning and to keep up with Rails 4:

DEPRECATION WARNING: The following options in your Title.belongs_to :lost_dct declaration are deprecated: :conditions. Please use a scope block instead. For example, the following:

    has_many :spam_comments, conditions: { spam: true }, class_name: 'Comment'

should be rewritten as the following:

    has_many :spam_comments, -> { where spam: true }, class_name: 'Comment'


So, no worries for the immediate future. 

Tim




To unsubscribe from this group and all its topics, send an email to hobousers+...@googlegroups.com.

Ignacio Huerta

unread,
Jan 30, 2014, 1:40:24 AM1/30/14
to hobo...@googlegroups.com
Thanks Tim, I'm glad it's not blocking. Anyway I hope it will get fixed
soon.

Regards,
Ignacio

El 29/01/14 20:32, Tim Griffin escribió:
> Ah, thanks Ignacio.
>
> Well, at least your hack is a very readable hack! Sorry to have found a
> bug. I know it's a good thing, but....
>
> This is not a blocking bug for me... I made the change just to silence
> the deprecation warning and to keep up with Rails 4:
>
> DEPRECATION WARNING: The following options in your Title.belongs_to
> :lost_dct declaration are deprecated: *:conditions*. Please use a scope
> > *Office: 202.296.7147 <tel:202.296.7147> | Mobile: 410.991.0811
> <tel:410.991.0811>*
> >
> > *Fax: 202.296.8903 <tel:202.296.8903> | email:** od...@barquin.com
> <mailto:od...@barquin.com> <mailto:od...@barquin.com
> <mailto:od...@barquin.com>>*
> >
> > BI_Logo_2012_JPEG
> >
> >
> >
> > NOTICE: If you have received this message in error, please contact the
> > sender immediately and be aware that the use, copying, or
> dissemination
> > of this information is prohibited. This email transmission contains
> > information from Barquin International that may be considered
> privileged
> > or confidential and is intended solely for the named recipient.
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > On Wed, Jan 29, 2014 at 1:29 PM, Tim Griffin
> <tim.g...@enwood.ca <mailto:tim.g...@enwood.ca>
> > <mailto:tim.g...@enwood.ca <mailto:tim.g...@enwood.ca>>> wrote:
> >
> > Whoops, Owen, thanks for finding my typo "2.0.1".
> >
> > But, I've been upgrading my app to *Hobo 2.1.0*, not 2.0.1, and
> > working against:
> >
> > gem 'activerecord', '~> 4.0.2'
> > gem 'activesupport', '~> 4.0.2'
> > gem 'rake', '0.9.2.2'
> > gem 'tiny_tds'
> > gem 'activerecord-sqlserver-adapter', :git =>
> >
> 'https://github.com/rails-sqlserver/activerecord-sqlserver-adapter.git',
> > :branch => 'master'
> > gem 'hobo_support', '2.1.0'
> > gem 'hobo_fields', '2.1.0'
> > gem 'pg', '0.17.1'
> > gem 'activerecord-postgresql-adapter', '~> 0.0.1'
> >
> > Tim
> >
> >
> >
> > On Wed, Jan 29, 2014 at 1:22 PM, Owen Dall <od...@barquin.com
> <mailto:od...@barquin.com>
> > <mailto:od...@barquin.com <mailto:od...@barquin.com>>> wrote:
> >
> > BTW, Hobo 2.0.1 has only been officially been tested with
> Rails
> > 3.x, not Rails 4.
> >
> > Hobo 2.1 (TBA) is being tested with Rails 4 by Ignacio.
> >
> >
> >
> > */
> > /*
> >
> > */
> > /*
> >
> > */
> > /*
> >
> > */-Owen/*
> >
> > */
> > /*
> >
> > *Owen Dall*
> >
> > *Vice President | Chief Technology Officer*
> >
> > *Barquin International*
> >
> > *Office: 202.296.7147 <tel:202.296.7147> | Mobile:
> 410.991.0811 <tel:410.991.0811>*
> >
> > *Fax: 202.296.8903 <tel:202.296.8903> | email:**
> od...@barquin.com <mailto:od...@barquin.com>
> > <mailto:od...@barquin.com <mailto:od...@barquin.com>>*
> >
> > BI_Logo_2012_JPEG
> >
> >
> >
> > NOTICE: If you have received this message in error, please
> > contact the sender immediately and be aware that the use,
> > copying, or dissemination of this information is prohibited.
> > This email transmission contains information from Barquin
> > International that may be considered privileged or
> confidential
> > and is intended solely for the named recipient.
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > On Tue, Jan 28, 2014 at 3:39 PM, Tim Griffin
> <te...@enwood.ca <mailto:te...@enwood.ca>
> > <mailto:hobousers%2Bunsu...@googlegroups.com
> <mailto:hobousers%252Buns...@googlegroups.com>>.
> >
> > To post to this group, send email to
> > hobo...@googlegroups.com
> <mailto:hobo...@googlegroups.com>
> <mailto:hobo...@googlegroups.com <mailto:hobo...@googlegroups.com>>.
> > Visit this group at
> http://groups.google.com/group/hobousers.
> > For more options, visit
> > https://groups.google.com/groups/opt_out.
> >
> >
> > --
> > You received this message because you are subscribed to a
> topic
> > in the Google Groups "Hobo Users" group.
> > To unsubscribe from this topic, visit
> >
> https://groups.google.com/d/topic/hobousers/LFPHsqTg8p0/unsubscribe.
> > To unsubscribe from this group and all its topics, send an
> email
> > to hobousers+...@googlegroups.com
> <mailto:hobousers%2Bunsu...@googlegroups.com>
> > <mailto:hobousers%2Bunsu...@googlegroups.com
> <mailto:hobousers%252Buns...@googlegroups.com>>.
> >
> > To post to this group, send email to
> hobo...@googlegroups.com <mailto:hobo...@googlegroups.com>
> > <mailto:hobo...@googlegroups.com
> <mailto:hobo...@googlegroups.com>>.
> > Visit this group at http://groups.google.com/group/hobousers.
> > For more options, visit
> https://groups.google.com/groups/opt_out.
> >
> >
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Hobo Users" group.
> > To unsubscribe from this group and stop receiving emails from it,
> > send an email to hobousers+...@googlegroups.com
> <mailto:hobousers%2Bunsu...@googlegroups.com>
> > <mailto:hobousers%2Bunsu...@googlegroups.com
> <mailto:hobousers%252Buns...@googlegroups.com>>.
> > To post to this group, send email to
> hobo...@googlegroups.com <mailto:hobo...@googlegroups.com>
> > <mailto:hobo...@googlegroups.com
> <mailto:hobo...@googlegroups.com>>.
> > Visit this group at http://groups.google.com/group/hobousers.
> > For more options, visit https://groups.google.com/groups/opt_out.
> >
> >
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Hobo Users" group.
> > To unsubscribe from this group and stop receiving emails from it, send
> > an email to hobousers+...@googlegroups.com
> <mailto:hobousers%2Bunsu...@googlegroups.com>.
> > To post to this group, send email to hobo...@googlegroups.com
> <mailto:hobo...@googlegroups.com>.
> > Visit this group at http://groups.google.com/group/hobousers.
> > For more options, visit https://groups.google.com/groups/opt_out.
>
> --
Reply all
Reply to author
Forward
0 new messages