active-hash / active_hash Goto Github PK
View Code? Open in Web Editor NEWA readonly ActiveRecord-esque base class that lets you use a hash, a Yaml file or a custom file as the datasource
License: MIT License
A readonly ActiveRecord-esque base class that lets you use a hash, a Yaml file or a custom file as the datasource
License: MIT License
e.g., right now one way to solve this is
after(:all) do # necessary so Context isn't messed up in other rspec contexts
Context.reload_active_file = true
end
hello, friend, I encountered a problem 'active_hash', eg:
class Template < ActiveHash::Base
include ActiveHash::Associations
has_many :job_type_templates, dependent: :destroy
has_many :job_types, through: :job_type_templates
self.data = [
.......
]
end
Template.first.job_types "ActiveRecord::StatementInvalid: Mysql2::Error: Unknown column 'job_types.template_id'"
Template.first.job_type_templates Correct
I should use eg:
def job_types
......
end
but don't support job_type_ids, thank you!
I have an ActiveHash model with ~17,000 records. Storing the records in an array and using Enumerable#detect
as the primary finder doesn't scale well to this level, so I propose changing the internal data store to a hash map of hashes. This would dramatically speed up .find_by_id
queries as id keys are looked up in constant time.
I've pushed a branch, hash_finder
, with my suggested changes. The public interface is the same, so data is still loaded in as an array of hashes but converted internally. This patch passes tests in all environments except for REE and Ruby 1.8.7 on Rails 2.2, which has some quirks in its implementation of ActiveSupport::OrderedHash
. (The OrderedActiveHash
class should eventually be the adapter for the different versions.)
Initial benchmarks show impressive speed gains for .find_by_id
queries but some modest losses for .where
queries. I know my dataset is unusually large, but perhaps the tradeoff may be worthwhile to others :)
The script I used for benchmarking is https://gist.github.com/3114439. Results for Ruby 1.9 are:
~/code/active_hash 1.9.3@active_hash [master]$ ruby benchmark.rb
user system total real
10th record id 0.010000 0.000000 0.010000 ( 0.012161)
10th record where 11.660000 0.010000 11.670000 ( 11.673704)
1000th record id 0.890000 0.000000 0.890000 ( 0.881761)
1000th record where 11.750000 0.010000 11.760000 ( 11.763799)
~/code/active_hash 1.9.3@active_hash [hash_finder]$ ruby benchmark.rb
user system total real
10th record id 0.010000 0.000000 0.010000 ( 0.000946)
10th record where 16.540000 0.020000 16.560000 ( 16.572191)
1000th record id 0.000000 0.000000 0.000000 ( 0.000934)
1000th record where 16.690000 0.020000 16.710000 ( 16.709648)
And for Ruby 1.8:
~/code/active_hash 1.8.7@active_hash [master]$ ruby benchmark.rb
user system total real
10th record id 0.010000 0.000000 0.010000 ( 0.013700)
10th record where 19.110000 0.010000 19.120000 ( 19.119064)
1000th record id 1.500000 0.000000 1.500000 ( 1.503936)
1000th record where 19.430000 0.010000 19.440000 ( 19.448877)
~/code/active_hash 1.8.7@active_hash [hash_finder]$ ruby benchmark.rb
user system total real
10th record id 0.000000 0.000000 0.000000 ( 0.001701)
10th record where 23.630000 0.020000 23.650000 ( 23.646547)
1000th record id 0.000000 0.000000 0.000000 ( 0.001752)
1000th record where 24.030000 0.010000 24.040000 ( 24.043448)
I'm open to comments, suggestions, and other ideas. Especially ideas about making older versions of OrderedHash
play nice.
probably adding field_before_typecast just to be consistent
Adding field :attributes
causes an immediate SystemStackError: stack level too deep
with one (useless) level of backtrace. (When running Cucumber it's somewhere in Cucumber; when running RSpec it's somewhere in RSpec.)
Probably the right thing to do is to raise a better error sooner, so the user knows what the real problem is.
Hi!
I need to store all states and cities and I prefer to not use DB for this. Searching for alternatives I've found this GEM. But as far as I understood it doesn't allow this kind of relationship between ActiveHash objects, right?
Thanks.
If there are only changes in the yml data, (such as no changes in model.rb)
how do I force a reload?
class Foo < ActiveHash
end
class Bar < AR
belongs_to :foo
end
class Buzz < AR
has_many :bars
has_many :foos, :through => :bars
end
Hi,
I'm developing a Rails 3.1.1 application. An ActiveRecord model belongs to an ActiveHash model. When I try to follow the relation in this way (AR -> AH), I get the following error:
undefined method 'scoped'
I hope this could help you,
Camille
Released active_hash gem version 1.2.1 depends on activesupport < 4, >= 2.2.2 (https://rubygems.org/gems/active_hash/versions/1.2.1) while version 1.2.0 only depends on activesupport >= 2.2.2 (https://rubygems.org/gems/active_hash/versions/1.2.0)
If I have in Gemfile
:
ruby '2.0.0'
gem 'rails', '~> 4.0.1'
gem 'active_hash', '~> 1.2.1'
Then I get this error when run bundle update
Bundler could not find compatible versions for gem "activesupport":
In Gemfile:
active_hash (~> 1.2.1) ruby depends on
activesupport (< 4, >= 2.2.2) ruby
rails (~> 4.0.1) ruby depends on
activesupport (4.0.1)
You are using ActiveModel, so bump the dependency to AR3+ otherwise it's kind of confusing when you get uninitialized constant ActiveModel
Just a quick reminder, this Gem isn't currently compatible with Rails 4.0. Trying to run it with Rails 4.0.0.beta1 will result in:
/(...)/activerecord-4.0.0.beta1/lib/active_record/reflection.rb:20:in `create_reflection': wrong number of arguments (4 for 5) (ArgumentError)
from /(...)/active_hash-ca2e9b625bce/lib/associations/associations.rb:32:in `belongs_to_active_hash'
That's because ActiveRecord::Reflection::ClassMethods.create_reflection
now receives a new 3rd argument, scope
: https://github.com/rails/rails/blob/master/activerecord/lib/active_record/reflection.rb#L20
whereas it seems to work with ActiveHash, ActiveYaml::Base objects don't seem to be ActiveRecord'able, I get :
uninitialized constant ActiveYaml::Associations
Thanks :)
def define_interrogator_method(field)
method_name = "#{field}?"
unless instance_methods.include?(method_name)
define_method(method_name) do
attributes[field].present?
end
end
end
how about just returning the boolean of the field like activerecord does?
a nice-to-have
find could still rely on it, but it wouldn't be coerced into an integer, for db's that use guids.
or maybe just a way to override id??
Have an ActiveRecord model which belongs_to an ActiveHash model. If the reference (id of the ActiveHash) is nil, the association raises an error -- this is inconsistent with ActiveRecord, which returns a nil association if the reference is nil.
Fixed in my fork (pull request sent):
http://github.com/jeremyw/active_hash/commit/458e3a014bde45d7e90fc650b2015bf96589fed8
class Country < ActiveHash::Base
end
class City < ActiveRecord::Base
belongs_to :country # => this doesn't work, it needs to be...
belongs_to_active_hash :country
end
I'm thinking to make this work, we could overwrite belongs_to
on ActiveRecord::Base, make it check to see if we are attempting to belong_to an ActiveHash object, and if so, just call belongs_to_active_hash
.
use Dir.pwd instead of File.dirname(FILE)
When this condition occurred and was encountered during execution of a rake task, it was difficult to trace back to the cause, since the web app was able to overcome this issue and ran fine.
The log just showed "Anonymous modules have no name to be referenced by" error and other errors that indicated initializers did not execute correctly, since the environment.rb with "config.gem" for active_hash, did not execute correctly, due to the condition in the subject line.
In lib/active_hash.rb you probably want only to require active_model if the version of Rails is 3.0 or greater.
Based on http://gist.github.com/164295 (thanks baldwindavid!)
foreign_key
works just fine, but primary_key always uses id
.
Given the following:
# app/models/state.rb
class State < ActiveHash::Base
include ActiveHash::Associations
has_many :cities, primary_key: 'abbrev', foreign_key: 'state'
self.data = [
{ id: 1, name: "California", abbrev: "CA" }
]
end
# app/models/city.rb
class City < ActiveRecord::Base
... # city.state would be "CA"
end
The following will fail because it looks for the value id
and not abbrev
s = State.find_by_name "California"
s.cities
The above would run something like:
SELECT "cities".* FROM "cities" WHERE "cities"."state" = 1
When it should run:
SELECT "cities".* FROM "cities" WHERE "cities"."state" = "CA"
I believe it should be fairly easy to add it to lib/associations/associations.rb
but I'm pretty green and unsure of all the implications.
foo belongs to bar
foo.bar = nil # => blow up on called ID for nil
This is because field_names
is nil, but .respond_to?
calls field_names.include?
.
module Enum
module Methods
def constant_for(field_value)
if constant = field_value.try(:dup)
constant.gsub!(/[^A-Za-z]+/, "_")
constant.upcase!
constant
end
end
end
end
I have an ActiveRecord model with a belongs_to association to an ActiveHash, which uses the :name field instead of :id for foreign key. When looking up the association, ruby complains with:
var/lib/gems/1.8/gems/active_hash-0.8.4/lib/active_hash/base.rb:201: warning: multiple values for a block parameter (2 for 1)
from /var/lib/gems/1.8/gems/activerecord-2.3.5/lib/active_record/associations/belongs_to_association.rb:49
It looks like ActiveRecord wants to pass some options to +find_by_name+, but the function as defined takes only one argument. Here's one way to fix it (in ActiveHash::Base):
def define_custom_find_method(field_name)
method_name = "find_by_#{field_name}"
unless singleton_methods.include?(method_name)
the_meta_class.instance_eval do
define_method(method_name) do |*args|
options = args.extract_options!
name = args[0]
all.detect { |record| record.send(field_name) == name }
end
end
end
end
By the way, here are the options being sent:
["Visa", {:include=>nil, :select=>nil, :readonly=>nil, :conditions=>nil}]
While find(_by_id) works fine. If I try to find by another attribute it fails until after I've run a find(_by_id).
This is concerning ActiveYaml
first it fails, then it works
ex:
TouchType.find_by_name "something"
NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.include?
from /opt/local/lib/ruby/gems/1.8/gems/active_hash-0.9.1/lib/active_hash/base.rb:139:inrespond_to?' from /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:380:in
all?'
from /opt/local/lib/ruby/gems/1.8/gems/active_hash-0.9.1/lib/active_hash/base.rb:138:ineach' from /opt/local/lib/ruby/gems/1.8/gems/active_hash-0.9.1/lib/active_hash/base.rb:138:in
all?'
from /opt/local/lib/ruby/gems/1.8/gems/active_hash-0.9.1/lib/active_hash/base.rb:138:inrespond_to?' from /opt/local/lib/ruby/gems/1.8/gems/active_hash-0.9.1/lib/active_hash/base.rb:145:in
method_missing'
from (irb):1
TouchType.find 1
=> #<TouchType:0x10367fbc0 @attributes={:name=>"something", :id=>1}>
TouchType.find_by_name "something"
=> #<TouchType:0x10367fbc0 @attributes={:name=>"something", :id=>1}>
Hello, I have the following models:
class User < ActiveRecord::Base
has_many :talks
has_many :languages, { through: :talks }
end
class Talk < ActiveRecord::Base
extend ActiveHash::Associations::ActiveRecordExtensions
belongs_to_active_hash :language
belongs_to :user
end
class Language < ActiveYaml::Base
include ActiveHash::Associations
has_many :talks
end
And everything's working perfectly. For instance:
@user = User.first #=> #<User id: 168, (...)>
@user.talks #=> [#<Talk id: 1, language_id: 1, user_id: 168, (...)>, (...)]
Except when:
@user.languages
(Object doesn't support #inspect)
However, this works well:
@user.talks.first.language #=> #<Language:0x007fcc8c298ac8 (...)>
I also have this backtrace from an rspec test:
(rdb:1) eval @current_user.talks
[#<Talk id: 1, language_id: 1, user_id: 1, level: nil, created_at: "2012-09-11 13:12:09", updated_at: "2012-09-11 13:12:09">]
(rdb:1) eval @current_user.talks.class
Array
(rdb:1) eval @current_user.languages
INTERNAL ERROR!!! undefined method `scoped' for Language:Class
/Users/cyril/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/active_hash-0.9.12/lib/active_hash/base.rb:218:in `method_missing'
/Users/cyril/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/associations/association.rb:123:in `target_scope'
/Users/cyril/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/associations/through_association.rb:15:in `target_scope'
/Users/cyril/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/associations/association.rb:87:in `scoped'
/Users/cyril/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/associations/has_many_through_association.rb:173:in `find_target'
/Users/cyril/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/associations/collection_association.rb:333:in `load_target'
/Users/cyril/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/associations/collection_proxy.rb:44:in `load_target'
/Users/cyril/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/associations/collection_proxy.rb:87:in `method_missing'
/Users/cyril/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/debugger-1.2.0/lib/ruby-debug/commands/eval.rb:47:in `block in execute'
/Users/cyril/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/debugger-1.2.0/lib/ruby-debug/commands/eval.rb:19:in `run_with_binding'
/Users/cyril/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/debugger-1.2.0/lib/ruby-debug/commands/eval.rb:46:in `execute'
/Users/cyril/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/debugger-1.2.0/lib/ruby-debug/processor.rb:275:in `one_cmd'
/Users/cyril/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/debugger-1.2.0/lib/ruby-debug/processor.rb:261:in `block (2 levels) in process_commands'
/Users/cyril/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/debugger-1.2.0/lib/ruby-debug/processor.rb:260:in `each'
/Users/cyril/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/debugger-1.2.0/lib/ruby-debug/processor.rb:260:in `block in process_commands'
/Users/cyril/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/debugger-1.2.0/lib/ruby-debug/processor.rb:253:in `catch'
/Users/cyril/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/debugger-1.2.0/lib/ruby-debug/processor.rb:253:in `process_commands'
/Users/cyril/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/debugger-1.2.0/lib/ruby-debug/processor.rb:173:in `at_line'
(eval):5:in `block in at_line'
<internal:prelude>:10:in `synchronize'
(eval):3:in `at_line'
/Users/cyril/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/debugger-1.2.0/lib/ruby-debug-base.rb:54:in `at_line'
/Users/cyril/code/Bonjour-Bonjour/spec/controllers/api/v1/private/my/users_controller_spec.rb:16:in `block (3 levels) in <top (required)>'
/Users/cyril/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example.rb:236:in `instance_eval'
/Users/cyril/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example.rb:236:in `instance_eval'
/Users/cyril/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/hooks.rb:23:in `run'
/Users/cyril/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/hooks.rb:72:in `block in run'
/Users/cyril/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/hooks.rb:72:in `each'
/Users/cyril/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/hooks.rb:72:in `run'
/Users/cyril/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/hooks.rb:424:in `run_hook'
/Users/cyril/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:323:in `run_before_each_hooks'
/Users/cyril/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example.rb:299:in `run_before_each'
/Users/cyril/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example.rb:112:in `block in run'
/Users/cyril/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example.rb:253:in `with_around_each_hooks'
/Users/cyril/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example.rb:110:in `run'
/Users/cyril/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:378:in `block in run_examples'
/Users/cyril/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:374:in `map'
/Users/cyril/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:374:in `run_examples'
/Users/cyril/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:360:in `run'
/Users/cyril/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:361:in `block in run'
/Users/cyril/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:361:in `map'
/Users/cyril/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:361:in `run'
/Users/cyril/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:28:in `block (2 levels) in run'
/Users/cyril/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:28:in `map'
/Users/cyril/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:28:in `block in run'
/Users/cyril/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/reporter.rb:34:in `report'
/Users/cyril/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:25:in `run'
/Users/cyril/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:69:in `run'
/Users/cyril/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:8:in `block in autorun'F/Users/cyril/code/Bonjour-Bonjour/spec/controllers/api/v1/private/my/users_controller_spec.rb:16
Thanks for your awesome work!
only skip if the interrogator is actually defined not if the getter is defined
Syntax or other errors that reference ActiveHash objects result in wiping all ActiveHash objects from server memory in a irrecoverable way. The only way to restore them is to restart the server, even in development mode. I am initializing about ~15 ActiveHash data structures in a single file in the /initializers directory. Is this expected behavior even in development mode? Shouldn't the data be re-initialized when the development server reloads? How can I minimize the risk of this happening in production mode? This occurs with both Webrick and Thin servers.
Here is an example, assume :gender_id is null:
Gender.find(gender_id).name
This call would result in an error, but also irrecoverably remove all ActiveHash objects from memory and require a server restart, even in development mode.
Object#respond_to? takes two arguments. The second argument is include_private.
This causes issues with rspec.
Thx,
Brian
I am trying to store Country with two languages. So I have :id, :name, :name_ch for every country. I found that if I use English characters for :name_ch, it let me access either name or name_ch with no problem. If I use Chinese character for :name_ch, it throws this error.
Syntax error, unexpected $end, expecting '}'
{:id => 1, :name => "China",:name_ch=>"**"},
Is there a fix for this? I think it is best if I can keep the translations in the hash data instead of having to declare them in i18n yml file.
Hi,
I can do ActiveHash -> ActiveRecord associations, but if I try ActiveRecord -> ActiveHash association, I get:
2.0.0p195 :002 > Student.last.gender
Student Load (1.4ms) SELECT `students`.* FROM `students` ORDER BY `students`.`id` DESC LIMIT 1
NoMethodError: undefined method `connection' for Gender:Class
from /Users/JozefVaclavik/.rvm/gems/ruby-2.0.0-p195/gems/active_hash-1.0.2/lib/active_hash/base.rb:225:in `method_missing'
from /Users/JozefVaclavik/.rvm/gems/ruby-2.0.0-p195/gems/active_hash-1.0.2/lib/active_file/base.rb:51:in `block (2 levels) in singleton class'
from /Users/JozefVaclavik/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-4.0.0/lib/active_record/associations/association_scope.rb:13:in `initialize'
from /Users/JozefVaclavik/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-4.0.0/lib/active_record/associations/association.rb:100:in `new'
from /Users/JozefVaclavik/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-4.0.0/lib/active_record/associations/association.rb:100:in `association_scope'
from /Users/JozefVaclavik/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-4.0.0/lib/active_record/associations/association.rb:84:in `scope'
from /Users/JozefVaclavik/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-4.0.0/lib/active_record/associations/singular_association.rb:42:in `find_target'
from /Users/JozefVaclavik/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-4.0.0/lib/active_record/associations/association.rb:139:in `load_target'
from /Users/JozefVaclavik/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-4.0.0/lib/active_record/associations/association.rb:52:in `reload'
from /Users/JozefVaclavik/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-4.0.0/lib/active_record/associations/singular_association.rb:9:in `reader'
from /Users/JozefVaclavik/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-4.0.0/lib/active_record/associations/builder/association.rb:70:in `gender'
from (irb):2
from /Users/JozefVaclavik/.rvm/gems/ruby-2.0.0-p195/gems/railties-4.0.0/lib/rails/commands/console.rb:90:in `start'
from /Users/JozefVaclavik/.rvm/gems/ruby-2.0.0-p195/gems/railties-4.0.0/lib/rails/commands/console.rb:9:in `start'
from /Users/JozefVaclavik/.rvm/gems/ruby-2.0.0-p195/gems/railties-4.0.0/lib/rails/commands.rb:64:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
# encoding: UTF-8
class Gender < ActiveYaml::Base
include ActiveHash::Associations
set_root_path "#{Rails.root}/config/data"
has_many :students
end
class Student < ActiveRecord::Base
...
belongs_to :gender
...
end
Any ideas?
That way we could do :
foo = Foo.new :size => 'large', :bitchinness => 'very'
foo.save
and then we could make Fixjour just work.
This also implies that new_record? should do the right thing and examine .data array.
Also:
Peter will help you with this
class User < ActiveRecord::Base
extend ActiveHash::Associations::ActiveRecordExtensions
belongs_to :class, ->(){ where( ) } #this is a ActiveRecord belongs_to
end
This will raise a "wrong number of arguments" error, on ActiveHash's belongs_to
currently we have to explicitly set field or call all()
After we upgraded from version 0.9.7
to 0.9.14
we started receiving the following error every time we try to update a record entry:
Duplicate Id found for record
The following test works at version '0.9.7' but stopped working at commit: ef5ee77
it "updates object in the data collection" do
Country.all.should be_empty
country = Country.new :id => 1, :name => "foo"
country.save
country.name = "bar"
country.save!
Country.all.should == [country]
end
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.