Replies: 11 comments 9 replies
-
So far, I'm very happy with how operations work. But I'm probably not the right person to ask because I have not yet used operations heavily (but I will in July, though). My main issue was with file uploads, which are mostly related to attributes and params, and we need those improvements before the real work can start. So I planned this week to implement them. |
Beta Was this translation helpful? Give feedback.
-
Particularly with save operations, I find associations to be a rough spot right now. Say I am making an app that has strong roles for its users. Just because a user can make, say, a new project, it doesn't mean that the project belongs to them, but they should be added as an admin of the project. To do this process with SaveOperations currently, I have to do something like: SaveProject.create(params) do |operation, project|
if project
SaveAdmin.create(project, current_user) do |operation, admin|
# success
end
end
end You can put the admin creation inside I don't have a good solution for this, or if others would even consider it a problem. |
Beta Was this translation helpful? Give feedback.
-
Just throwing some more info out there. I know @fernandes has mentioned we could take some inspiration from http://trailblazer.to/. For me, I see the Operations similar to the ruby mutations. I know everyone will have their different opinions on how the code should look and function, but I think as long as the end result doesn't hinder or block you from being able to accomplish your end goal, then we're fine. We're starting to take this approach of "Here's how we think you should do it..." but then "here's how you can escape out if you want to do it different". If you have an example of how you'd do this in another framework that you really enjoyed, feel free to pop it in here. Maybe it'll spark some ideas on an interface that would be great for Lucky! |
Beta Was this translation helpful? Give feedback.
-
With Boxes, associations are an issue as well. I believe that all associations should be preloaded/included by default. Beyond that, though, I think they need to be more opinionated. Right now they are just SaveOperations and there are ways to do trait style creation and to pass in associations but it is all with standard Crystal. This is nice, but it also means that it's not apparent the best way to use them. I'm thinking of ruby's factory_bot and the clear DSL it has for creating and using factories for generating data. |
Beta Was this translation helpful? Give feedback.
-
If I think hard about it, I am sure I could come up with more, but here a two things I encountered this week:
|
Beta Was this translation helpful? Give feedback.
-
Just dropping this bit luckyframework/avram#413 |
Beta Was this translation helpful? Give feedback.
-
Another nice-to-have, not essential at all, but since we are at it 😁 I like being able to have seperate operations for creating and updating records. Sometimes I need this, e.g. when there are attributes that should not be changed once the record has been created. So currently I would have my But technically both would still allow to use them for creating and updating. It might be nice to be able to choose if you want only one of those capabilities or both. |
Beta Was this translation helpful? Give feedback.
-
Left a comment on luckyframework/avram#413 before my attention was drawn to this discussion: luckyframework/avram#413 (comment)
|
Beta Was this translation helpful? Give feedback.
-
Just a thought with regards to luckyframework/avram#410: In save operations, there could be a In future, if there are other default validations, such as validating uniqueness of columns with "UNIQUE" constraint, there could be a This should allow for fine-grained skipping of default validations, without needing to turn off the entire feature. I find the existing feature useful, as it may prevent inadvertent database errors at runtime. At the same time, I have run into situations where I needed to turn it off for a specific attribute. For instance, one may not want to tell a user that " |
Beta Was this translation helpful? Give feedback.
-
@jwoertink I know we've discussed this in the past somewhere, but I couldn't seem to track it down... I think it'd be worthwhile in this change to consider namespacing operations in the generated app and operation generators similarly to how we namespace pages/actions, since they are used quite closely with both. I've found that my top-level operations folder can get a bit cluttered, but I feel a bit like I'm going against the "Lucky way" if I manually refactor the |
Beta Was this translation helpful? Give feedback.
-
I think there's an opportunity to make the It would allow us to register callbacks that subclasses can plug in to. abstract class BaseClassWithCallbacks
include Avram::Callbacks
register_callback :before_it
register_callback :after_it, status : Int32
def task
call_before_it # adding the `call_` is the best I could do to get it running
status = do_it
call_after_it status
end
end
class MyClass < BaseClassWithCallbacks
before_it :do_something
before_it :do_something_else
after_it :finish_up
...
end This would immediately be applicable to adding more callbacks than |
Beta Was this translation helpful? Give feedback.
-
Right now Boxes are created from SaveOperation, and those are inherited from Operation. For me, I use the base Operation a lot, but they require a ton of work when not associated to a model. For this reason, I started a PR to refactor how they work. I had to put this on hold due to a Crystal bug which was solved in 0.35.0. This means that after this next Lucky release, I can get back on to this.
Before doing that, I've noticed a lot of new issues and PRs come up surrounding these concepts to try and update them. To me, it sounds like maybe we need to take a step back and rethink how we want this whole system to work, rip it out to the studs, and then renovate it to be amazing before we hit 1.0.
luckyframework/avram#403
luckyframework/avram#407
luckyframework/avram#404
luckyframework/avram#334
luckyframework/avram#385
luckyframework/avram#377
luckyframework/avram#376
luckyframework/avram#374
luckyframework/avram#371
luckyframework/avram#331
luckyframework/avram#313
luckyframework/avram#298
These aren't even all of them, just some of the PRs and issues I came across.
Discussion
What I'd like to discuss here is, what are your pain points with SaveOperation / What does a "perfect world scenario" API for saving / updating records look like to you? What thing should this do, and what things shouldn't this do? Is the current API pretty close with a few tweaks for you, or do you just dread when you get to this section of your code?
Beta Was this translation helpful? Give feedback.
All reactions