softace / activerecord-tableless

Bringing together the different tableless model implementations into a single gem/plugin
Other
113 stars 41 forks source link

Can't use #build method on class and association #13

Closed Fire-Dragon-DoL closed 10 years ago

Fire-Dragon-DoL commented 10 years ago

As stated in the title, if I run MyModel.build(name: 'test') I get an error:

undefined method `build' for MyModel(Table doesn't exist):Class

My class is this:

require 'activerecord-tableless'

class MyModel < ActiveRecord::Base
  has_no_table

  # Stands for MenuID
  column :mid, :string

  def find_by_mid(identifier)
    MyModel.build(mid: identifier)
  end

end

Model is quite simple, I tested even with :database => :pretend_success but same error.

I'm on rails 4.0.2, I would like to help but I'm having a lot of troubles setting up the test suite for the gem :\

jarl-dk commented 10 years ago

Sorry. This one has slipped my eyes, I will take a look at it.

Fire-Dragon-DoL commented 10 years ago

No problem, thanks for watching at it

jarl-dk commented 10 years ago

It seems like you are using AR incorrect: You can't use #build on the class. #build is ment to be used on associated children.

You can probably get what you want by changing MyModel.build(mid: identifier) to MyModel.create(mid: identifier) or MyModel.new(mid: identifier)