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
Hanami 0.9.x compatibility #1
Comments
It might be worthwhile to take a look at shrine-rom-example, which includes a plugin for ROM (which I imagine is similar). However, it currently requires the model instance to have an Anyway, just putting it out there, as I think whichever ideas come up with hanami-shrine, it could also be ported to shrine-rom (which should at some point be released as a gem), and vice versa. |
@janko-m Thanks for the link! I looked through it, but my problem is more related to the fact that the entity is frozen and does not define setter methods, i.e. you have to pass everything in the constructor and it cannot change. For example, it does not have I played around with That being said, I'm even closer to be certain that "usual" file upload is now impossible to achieve in Hanami. Which is definitely not good. @jodosha, perhaps you could help us here a bit? |
@katafrakt Can't you have the method on an other object (say |
Yes, neither do the dry-rb models that are used in shrine-rom-example; I added the |
@katafrakt Your plugin could override def set(uploaded_file)
@old = get
data = convert_to_data(uploaded_file) if uploaded_file
data = data ? convert_before_write(data) : nil)
record.class.new(record.to_h.merge(data_attribute => data))
validate
end (it would actually be better to override def write(value)
record.class.new(record.to_h.merge(data_attribute => value))
end |
@myabc That sounds like a great idea! And good question – in Shrine private methods don't equate to private API. Actually, there aren't really methods that are part of private API, almost every method from base is used or extended in plugins, so they have enough "weight" that it's very unlikely they will be removed. |
Hi all! I'm not familiar on how This should be injected by def initialize(attributes = nil)
# prepare attributes for shrine
super(attributes)
end or alternatively to have this in native def update(new_attributes)
self.class.new(attributes.merge(new_attributes))
end Is that attribute part of the database columns or is it a virtual attribute? For instance, given a A "virtual attribute" is an attribute that is not backed by a corresponding database column. Eg. You try to set I'm asking because entities now whitelist the attributes received when initialized. This is done by an internal schema. This schema is modeled around the corresponding database table. If you use concrete attributes, you're all set. If you don't (virtual), we should work together to add an extension point in /cc @davydovanton |
@jodosha Thanks for your comments!
I like the approach with creating a new entity before save ( |
upgrading my project to hanami-0.9 this week, I took a 'bad' or 'bull in a china shop' approach:
and
But I would very much like a better solution. I'm guessing/worried that 'disabling' entity freezing might have some downstream effects, other than snubbing dry-rb software design patterns. |
@nessur Thanks for sharing and letting me know that you are using this project! I'm still working on a proper solution and I think I'm getting closer and closer to the solution. This will require some changes in the API for sure, but (I hope) won't include any hacks like overwriting |
Adding @davydovanton and @cllns to this conversation. |
I created a pull request for adding support for Hanami 0.9: see #2 I know the code is kind of unclear, but I'd appreciate any kind of code review. |
Latest Hanami release, specifically new model engine, broke hanami-shrine heavily. This was expected, but not to that extent. Right now I have run out of ideas on how to proceed.
Problem:
Attacher
class, see here.attachment=
, but newHanami::Entity
does not call it on initialization. As a result, I gotcan't modify frozen Entity
.Solution I can think of:
Add some kind of
after_initialization
callback before freezing entity. This would allow hanami-shrine (and possibly other gems integrating with hanami-model) to do their job before freezing. I know it sounds a bit Railsy.I create the issue in this repo because I think this is not exactly Hanami problem, but it may happen that it can only be resolved by Hanami team. Of course, any suggestions on how to approach the problem differently are welcome.
The text was updated successfully, but these errors were encountered: