Displaying 2 results from an estimated 2 matches for "myactiverecord".
Did you mean:
activerecord
2012 Jan 04
1
AR update / create pattern: is there an easier way?
I find myself writing the following frequently:
r = MyActiveRecord.where(:attr1 => cond1, :attr2 => cond2, ...)
r.exists? ? r.first : r.create
... which has the effect of returning an instance of MyActiveRecord if
all the conditions are met, or creating one if it doesn''t. A variant of
this:
c = MyActiveRecord.new(:attr1 => val1, :attr2...
2004 Nov 19
18
SingleTableInheritance Considered Harmful
...Active Records?; one connects to one database, one to another. I
don’t want to have to add the connection code to every single Active
Record subclass I create when I could consolidate it into two abstract
classes.) Or you will be once you convince Active Record to ditch the
inheritance:
class MyActiveRecord << ActiveRecord::Base
def self.descends_from_active_record?
true
end
end
Or, if you still don''t understand relational databases and insist
on using Single Table Inheritance, but still need an abstract class
between you and Active Record, you can
def self.descends_fro...