Comments (9)
Hello @simonasdev ,
first, thanks for nice report. I think you really found a bug. The tricky part is that when you ask enum attribute for value it will return you the value from array and not the value which comes to database.
I will try to look on it. For now you can use a workaround with proc. It should work that you will change your validation definition like this
validates :valid_from, :valid_until, overlap: {
exclude_edges: ['valid_from', 'valid_until'],
scope: ['object_parameter_id', 'resource_id', 'resource_type', kind: -> { |obj| obj.read_attribute(:kind) }]
}
Let me know if it helped.
from validates_overlap.
Ok,
so I changed the send
method to read_attribute
if you will now set gem source from github then everything should start work with the validation definition as you had.
Let me please know if it helped
from validates_overlap.
Try to update to 0.5.2 .
from validates_overlap.
I updated the Gemfile and it did start working, thanks a lot. This should be sufficient, since we can always use lambdas to overwrite the default read_attribute
. Hopefully it didn't break anyone else's code.
from validates_overlap.
Hi @robinbortlik, This bug fix is not working in Rails 5. read_attribute
is returning values of enum after typecast. Only way i found to get the integer value is to use "read_attribute_before_typecast", but this breaks other columns like date.
Currently, I am using the passing the following proc to scope in my model as a workaround. My enum is named day.
:scope => {"day" => proc{|object| object.class.days[object.day] } }
As an aside, I am unable to declare procs when passing an array to the scope.
For instance, this is not working
:scope => ["attr1", attr2: => proc{|obj| obj.some_value}]
This is the workaround i am using to use regular scope along with proc
:scope => {"attr1" => 'false', attr2: => proc{|obj| obj.some_value}}
Is this the expected behaviour? If yes, I think the readme needs to better reflect it. Let me know what you think and i will update the readme.
Code in the gem dealing with arrays and hashes in scope
def add_attributes(record, attrs)
if attrs.is_a?(Array)
attrs.each { |attr| add_attribute(record, attr) }
elsif attrs.is_a?(Hash)
attrs.each do |attr_name, value|
add_attribute(record, attr_name, value)
end
else
add_attribute(record, attrs)
end
end
from validates_overlap.
Hi @tejamedasani I can take a look, but I' pretty busy at this moment, so it will not be earlier then next week or maybe week after. The PRs are always welcome.
from validates_overlap.
Hi @tejamedasani the bug should be fixed by #38 . You can update gem version to 0.8.1
and everything should work.
from validates_overlap.
from validates_overlap.
Hello, @robinbortlik i'v just found this bug again.
class Lession < ApplicationRecord
enum day: {
monday: 0,
tuesday: 1,
wednesday: 2,
thursday: 3,
friday: 4,
saturday: 5,
sunday: 6
}
validates :start_at, :end_at, overlap: { exclude_edges: ["starts_at", "ends_at"], scope: [:day]}
end
in that case function is_enum_attribute?
will return false, because record.class.defined_enums[attr_name.to_s].present?
return false.
But, if use scope: ['day']
methods above will return true.
Rails 5.1.4
validates_overlap at master@7be2f5e
PR Attached
Thanks.
from validates_overlap.
Related Issues (20)
- Possibility to add a scope HOT 2
- Support for nil? HOT 10
- A bug if the second object is contained entirely inside one that is already persisted HOT 3
- Should we index these database calls? HOT 1
- Overwriting an existing time_overlap HOT 2
- Gemspec clearing HOT 3
- Allow Edges seems broken HOT 5
- Right behaviour or bug? HOT 6
- Skip HOT 3
- Start_in date field cannot be nil HOT 7
- How to get conflicting records? HOT 8
- Explanation HOT 4
- Prevent date range inside of another date range HOT 4
- Active Model Errors HOT 5
- Allow override of validation HOT 2
- Accessing overlapped records in validation message HOT 8
- Missing value while forming the SQL prepared statement HOT 3
- Rails 6 scoping deprecation warning HOT 4
- scope with enum symbol causing `undefined method `[]' for nil:NilClass`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from validates_overlap.