pyromaniac / active_data Goto Github PK
View Code? Open in Web Editor NEWWorking with any data in AR style
License: MIT License
Working with any data in AR style
License: MIT License
Consider a model with references inside embedded collection:
class Example
include ActiveData::Model
embeds_many :users do
references_one :user
end
end
accessing users
causes 1 model query per each element of the users
collection.
Add the preload
method to eagerly preload selected associations to avoid N+1's queries.
I've typically used Virtus for form objects and mimicking an ActiveModel API in general. On the surface, the two libraries appear to have similar goals.
I recommend adding a brief note to the readme that compares this library to Virtus. It would help casual passersby, like me, understand why they should spend time investigating. Of course, I'm assuming you want more Internet randos using your library and that you made specific design decisions to be different from Virtus. Neither may be true. 😛
Anyway, code looks clean from my brief skimming, but I don't really have any friction points with Virtus motivating me to seek out new solutions in this area. Cheers.
Not always, but sometimes I can see in my Airbrake
https://www.dropbox.com/s/mh5zvnl4zcyjs8o/Screenshot%202015-11-16%2022.24.24.png?dl=0
Params: { "action": "index", "controller": "search" }
Code:
https://www.dropbox.com/s/i3g0yqw79tt588g/Screenshot%202015-11-16%2022.25.23.png?dl=0
Don't know how to reproduce. I can add something like "obj || {}" and make PR, but I think issue is different
If you will tell me how to reproduce and suggest dirrectio how to fix - I can make PR
I'm trying to run some method after initialize and it's giving me the following:
NoMethodError at /api/v1/search
=====================================
> undefined method `after_initialize' for Search:Class
According to this, I should be able to do the following:
class Search
include ActiveData::Model
after_initialize :define_qualifiers
...
I've been tracking master for a bit since there've been 200+ commits since 0.3. Could you cut a new version to rubygems? Thanks!
In Rails 5, Ruby 2.3 @ /lib/active_data/active_record/nested_attributes.rb:7
Please, use Module#prepend instead. From module, you can access the original method using super. (called from block in <module:NestedAttributes> at /usr/local/bundle/bundler/gems/active_data-949dc14bb8cc/lib/active_data/active_record/nested_attributes.rb:7)
class Foo
embeds_one :subfoo do
end
end
Add an ability to use Foo::Subfoo
directly, using const_missing
.
🐹 yo!
class Yo
include ActiveData::Model
end
[Yo].flatten
# => []
describe Yo do
it 'fails' do
false.should be_true
end
end
# => " fails"
After updating to ActiveData 0.3.0 I am now receiving the following error when trying to run rails c
:
/vendor/bundle/ruby/2.1.0/bundler/gems/active_data-10a2aef9bd81/lib/active_data/model/primary.rb:6:in '<module:Primary>': uninitialized constant ActiveData::UUID (NameError)
The ActiveModel::Errors class has changed, keeping most of the high level API compatible, but some of the underlying implementation are not working anymore.
The class ActiveData::Model::Validations::NestedValidator
is not compatible with the new implementation, it should be something on the lines of:
def self.validate_nested(record, name, value)
if value.is_a?(Enumerable)
value.each.with_index do |object, i|
if yield(object)
object.errors.each do |error|
record.errors.import(error, attribute: "#{name}.#{i}.#{error.attribute}")
end
end
end
elsif value && yield(value)
value.errors.each do |error|
record.errors.import(error, attribute: "#{name}.#{error.attribute}")
end
end
end
but of course this only works with the new errors interface… so maybe a version check? I haven't been able to find a version-independent way to achieve it.
When testing my app against the latest Rails 5.0 beta, I noticed a deprecation warning being called within active_data:
DEPRECATION WARNING: alias_method_chain is deprecated. Please, use Module#prepend instead. From module, you can access the original method using super. (called from block in module:Callbacks at /lib/active_data/model/callbacks.rb:48)
I'm not sure that I have the dev chops to open a pull request to fix this, but thought I should bring it to your attention in the event that you were not aware. Thanks!
class MyClass
include ActiveData::Model
attribute :id, type: String, default: proc{SecureRandom.uuid}
end
my_class = MyClass.new
pp my_class.id
pp my_class.id
"f50d373d-16b8-436a-a36c-d8c6903994d8"
"1fca043d-39f1-4e9f-9f01-87295e24ae48"
I think, id has to be same each time as we call read_attribute on the same object. What do you think?
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.