Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some read-only DPs return false for "read_only?" #1399

Closed
prioux opened this issue Jun 18, 2024 · 5 comments
Closed

Some read-only DPs return false for "read_only?" #1399

prioux opened this issue Jun 18, 2024 · 5 comments

Comments

@prioux
Copy link
Member

prioux commented Jun 18, 2024

Some DPs are meant to be read-only. Usually, they inform the rest of the system by just overriding the method read_only() in this way:

def read_only
   true
end

The attribute read_only is a database column. However, for boolean columns, Rails also provide read_only? . Since that method is not overridden, it returns false if the DB's value has not been set. So we get this kind of behavior:

irb> d.read_only
 => true 
irb> d.read_only?
 => false 

There are several solutions. Not sure what is best.

  1. make sure the DB column is also consistent; maybe with a general callback in after_update() ?
  2. override read_only? too
  3. ...
  4. profit!
  5. my slashdot ID is 5 digits long
@MontrealSergiy
Copy link
Contributor

MontrealSergiy commented Jul 8, 2024

Well, I would go for variant 2 because it is probably enough to override read_only? method in the parent class and it affects the method immediately on creation. Also, optionally, variant 1 can be implemented in the same time, just to make database more consistent

@MontrealSergiy
Copy link
Contributor

MontrealSergiy commented Jul 17, 2024

Actually not only boolean, any attribute has #{attribute}? 'truthiness/presentishness' check method, which differs only in question mark, something like name?, type?, description? etc ... Note integer 0 considered as falthy value.

@MontrealSergiy
Copy link
Contributor

@prioux Should I work on it, or would you prefer to take care of it yourselves?

@prioux
Copy link
Member Author

prioux commented Sep 9, 2024

Fixed all the DPs with an explicit

def read_only?
   true
end

@prioux prioux closed this as completed Sep 9, 2024
@prioux prioux self-assigned this Sep 9, 2024
@prioux
Copy link
Member Author

prioux commented Sep 9, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants