2
votes

I'm using rails 4.2.5 with postgresql.

I have a model like this:

class PlatformLink < ActiveRecord::Base
  belongs_to :platform
  belongs_to :download_link
end

class Platform < ActiveRecord::Base
  has_many :platform_links
  has_many :download_links, through: :platform_links
end

class DownloadLink < ActiveRecord::Base
  has_many :platform_links
  has_many :platforms, through: :platform_links
end

Now, I have a form with a few checkboxes, in which I can select which platforms are connected to a certain download_link, that populates parameters like this:

{ :download_link => { :id => 7, :platform_ids => ['2', ''] } }

And I do:

download = DownloadLink.find(7)
download.platform_ids = download_params[:platform_ids]
download.save!

The problem is, after saving, my model does not create any relation between platform id 2 and this download_link.

I tried to isolate the problem like this, and I noticed this. This is working correctly:

DownloadLink.create(platform_ids: ['2'])

BUT this:

download = DownloadLink.find(something)
download.platform_ids = [2, 3]
download.save

...does absolutely nothing.

What could be the cause for this?

How about putting a ! on that last save? - Dave Schweisguth
I tried, no change... - ProGM
For @smathy : I'm not the downvoter. o.o' - ProGM
I'd be looking at the generated SQL at this point. - Dave Schweisguth