active_record-acts_as icon indicating copy to clipboard operation
active_record-acts_as copied to clipboard

Does attributes order matter on creation?

Open karellm opened this issue 10 years ago • 2 comments

Hi,

I'm a little confused with this bug. First some code:

class Company < ActiveRecord::Base
  acts_as :entity
  has_many :company_markets
  has_many :markets, through: :company_markets

  def market_ids
    # getter for market_ids
  end

  def market_ids=
    # setter for market_ids
  end
end

class Entity < ActiveRecord::Base
  # as a name attribute
  actable
end

I should also add I have a non-null constraint on the entity.name database table row.

Now the confusion:

Company.create(market_ids: [1, 2], name: 'test') will fail throwing PG::NotNullViolation: ERROR: null value in column "name" violates not-null constraint meaning the entity was created without the name I gave it.

But Company.create(name: 'test', market_ids: [1, 2]) will work. Huh?

So I was curious if that a normal behaviour or not. If not I could look at the code and do a PR. Let me know.

karellm avatar Jan 05 '15 14:01 karellm

It is a bug. And PR is welcome :-)

hzamani avatar Jan 06 '15 14:01 hzamani

I have actually decided to change my DB design and won't need this gem anymore. So I won't work on the PR but will leave this open so you can address it eventually. Thanks for the good work. Cheers!

karellm avatar Jan 10 '15 06:01 karellm