Open jibiel opened 10 years ago
I'll take a look at it...
This interests me too, did you find anything?
Sorry guys... I have been busy. I'll see if I can find some time...
However at first glance I see that your parent model Store
has a table, whereas your child model Report
does not have a table. Can you try this with the parent model also being tableless, please?
@jarl-dk Ok, here's the new model:
class Reportable < ActiveRecord::Base
has_no_table
has_one :report, as: :reportable
column :smth, :string
end
The other two are still the same (though I've added polymorphic association, just ignore that).
Here's what we have:
> Store.take.build_report # Store «has_table»
Store Load (0.6ms) SELECT "stores".* FROM "stores" LIMIT 1
NoMethodError: undefined method `sanitize_limit' for #<Object:0x007fd5b9838560>
from /Users/jibiel/.rvm/gems/ruby-2.0.0-p481@smth/gems/activerecord-4.0.0/lib/active_record/relation/query_methods.rb:808:in `build_arel'
> Store.new.build_report # Store «has_table»
=> #<Report reportable_id: nil, reportable_type: "Store", period: Sun, 01 Jun 2014 21:18:39 MSK +04:00..Tue, 01 Jul 2014 21:18:39 MSK +04:00>
> Reportable.take # Reportable has_no_table
NoMethodError: undefined method `sanitize_limit' for #<Object:0x007fd5b98f0ed0>
from /Users/jibiel/.rvm/gems/ruby-2.0.0-p481@smth/gems/activerecord-4.0.0/lib/active_record/relation/query_methods.rb:808:in `build_arel'
> Reportable.new.build_report # Reportable has_no_table
=> #<Report reportable_id: nil, reportable_type: "Reportable", period: Sun, 01 Jun 2014 21:18:39 MSK +04:00..Tue, 01 Jul 2014 21:18:39 MSK +04:00>
That is nothing new. I mean, I can't take
tableless object, right?
I suppose, that is not a big deal if I'm the only one concerning. I imagine that the concept is difficult enough without the thing I'm asking.
Meanwhile, we use simple workaround at the office:
class Store < ActiveRecord::Base
# ...
def report
Report.new reportable: self
end
end
> Store.take.report # Store «has_table»
Store Load (0.6ms) SELECT "stores".* FROM "stores" LIMIT 1
=> #<Report reportable_id: 321, reportable_type: "Store", period: Sun, 01 Jun 2014 21:31:35 MSK +04:00..Tue, 01 Jul 2014 21:31:35 MSK +04:00>
I have created a PR #24 which fixes this issue for me. Not heavily tested, though.
@jarl-dk ActiveRecord::Tableless
is a fine gem
. I personally use it for every rails
project when migrating from other frameworks, like CodeIgniter
, WordPress
, etc. Have you thought about assigning more Collaborators / Maintainers? You could pick someone from the forks.
@jarl-dk I find myself reaching for this gem on most projects as well. Please ask for help maintaining if you are no longer able to do it effectively.
I also need to understand how to build associations to has_no_table
models properly.
Greetings.
Currently I'm trying to initialize object through
has_one
association like this:But getting only:
Is this currently supported? Could you please provide an example?
I suspect this is rather me not understanding things than lack of implementation. Anyways, it'll be great to see such example in the
README.md
.Thanks.