Has many through problems

20 views
Skip to first unread message

Tim Uckun

unread,
Aug 27, 2012, 10:55:18 PM8/27/12
to actives...@googlegroups.com
Hey Guys.

I have this setup.

Pma
has_many :pma_maps
has_many :pma_locations, :through => :pma_maps

If I put pma_locations in the column list it shows the locations but
if I click on the list I get this error NoMethodError (undefined
method `klass' for nil:NilClass):

I tried with a nested link like this

conf.nested.add_link(:pma_locations, :label => "Locations", :page => false)

and I get the same error.

If I manually fetch the locations Pma.first.pma_locations I get a list
no problem.

nested link seems to be working just fine for has many but it's having
problems with through.

Tim Uckun

unread,
Aug 28, 2012, 11:16:24 PM8/28/12
to actives...@googlegroups.com
Hey guys hate to bump my own post but does anybody have a clue on how
to proceed with this?

The wiki page on has_many :though is blank too

Cheers.

Sergio Cambra

unread,
Aug 29, 2012, 3:52:26 PM8/29/12
to actives...@googlegroups.com
I have tested and it works, in master branch. Can you post your models (pma, pma_map and pma_location)?

Tim Uckun

unread,
Aug 29, 2012, 5:43:35 PM8/29/12
to actives...@googlegroups.com
class Pma < ActiveRecord::Base
attr_accessible :name, :status

belongs_to :division
belongs_to :dealer
has_many :pma_maps
has_many :pma_locations, :through => :pma_maps

def to_label
name
end
end


class PmaMap < ActiveRecord::Base
attr_accessible :pma_location_id, :pma_id
belongs_to :pma_location
belongs_to :pma

def to_label
"location: #{pma_location_id}, Pma:#{pma_id}"
end
end


class PmaLocation < ActiveRecord::Base
attr_accessible :post_code, :suburb

has_many :pma_maps
has_one :pma, :through => :pma_maps

def to_label
"#{suburb} #{post_code}"
end
end
> --
> You received this message because you are subscribed to the Google Groups
> "ActiveScaffold : Ruby on Rails plugin" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/activescaffold/-/IOmMEHjsTgUJ.
> To post to this group, send email to actives...@googlegroups.com.
> To unsubscribe from this group, send email to
> activescaffol...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/activescaffold?hl=en.

Sergio Cambra

unread,
Aug 30, 2012, 2:46:45 AM8/30/12
to actives...@googlegroups.com
I got this error trying to create PmaLocation from Pma:
Cannot have a has_one :through association 'PmaLocation#pma' where the
:through association 'PmaLocation#pma_maps' is a collection. Specify a has_one
or belongs_to association in the :through option instead.

Changing association to has_many :pmas, :through => :pma_maps works.
Reply all
Reply to author
Forward
0 new messages