Can I use different adapters for different models? - active-model-serializers

Is it possible to specify different active-model-serializers adapters for different models?
Based on my reading, the gem only seems to allow the initialization of an app-wide adapter.
Does anyone have any experience with this?

You can specify the adapter like this:
render json: #post, serializer: PostPreviewSerializer, adapter: :json_api

Related

Is it a good practice to use a converter inside a populator?

Hybris tell us that Converters should use populators and not vice versa because can be critical for performance considerations.
But when I am digging in hybris code you can see populators like DefaultAbstractOrderEntryPopulator, ProductFeatureListPopulator which
are wiring converters.And I have also find Populators using other populators such as ProductPopulator.
I read the following links but I cannot find anything about using a converter inside a populator or populator inside of populators:
Wiki Hybris - Converters and Populators
Wiki Hybris - DTOS best practice
Wiki Hybris 6
so, can we use converters inside populator like Hybris does? and populators inside populators?
I would like to give my point of view to answer this question. One common mistake when working with converters and populators is to confuse them.
Converters creates a DTO and populators filling the DTO.
We have to be very careful when we are going to use a converter inside of a populator and to be completely sure that
we need to do that.
If we have a long chain of populators using converters we can have a performance risk. For instance
C1->P1->C2->P2->C3->P3....
I think the best practise to follow is:
1) Be aware of the converters are already done, and ckeck if we have to add our populator to an existing Converter
(for example using the modifyPopulatorList)
2) If our DTO has another dependency with other DTO
We should ask ourselves if that dependency it is really necessary.I will decide this according to if that second DTO is used in many places
or not.Because if you are the only one who use it maybe you can merge the properties in only one DTO and avoid to have two different converters.
3) Other possibility It is to use differents converter in parallel as we can see in
WIKI HYBRIS - Facades and DTOs
To sum up, the design of our converters and populators is our responsability, and we have to get the best design posible of them to avoid
performance problems.
Basically the way to do it is: never write a concrete converter class and never call a populator directly.
But this is how the product is built for extensibility and frankly you can do whatever you like.

Helper in NodeJS+CompoundJS

I'm just starting out in CompoundJs and there's a lot I still need to learn.
I'm just trying to figure out how Helpers work in NodeJS+CompoundJS, from what I've seen so far Helpers are intended to be used with Views and not so much with your Controllers.
However I would like to make a simple function that will validate the user input given in params (check if certain params are defined and optionally check if their value is valid).
Can anyone explain to me what would be the best way of implementing this? Keeping in mind that I will want to use this in many different controllers so it should be globally available.
Do i have to use custom validator or helper?
Validation is probably better suited for the model. You could also do lower-level validation in the controller. The helpers are just designed for exposing global variables to the view templates.

generalizing classes or not when using mapper for database

lets say i have the following classes:
customer, applicant, agency, partner
i need to work with databases and use mappers to map the objects to the database. my question is, can i generalize these classes with the class person and just implement a mapper for this class? basically it would look like this:
instead of this:
the mapper classes use orm to save and edit fields in the database, i use them because the application i am doing has to be developed further in the future.
If each of the classes (Partner, Applicant, etc.) has different attributes, you can't have only one mapper for all of the classes (well, you can, but then you would have to use meta-programming to retrieve information from the classes lower down the hierarchy). The solution also depends on how and who manages your database: do you have control over how it is designed or is it something that you cannot change? in the second case I would definitely use a mapper per class to allow full decoupling between DB and app. In the first case, you could use some kind of mapping hierarchy. And also, it depends on what language/frameworks you are using.
Good Luck!

Cakephp Search Plugin from CakeDC

Has anyone incorporated the Seach plugin from CakeDC?
I am a confused as in how it has to be used. I am creating a Seach Controller and trying to search all models from there.
In the Wiki, it states that I should create a $filterArgs variable on my models. Should I have public $filterArgs in every model or should only at one place?
If there is a tutorial can someone point me to it?
Should be in each model. The controller, which generally uses only one model, then uses it. I've had nothing but trouble trying to make one controller handle multiple models, apart from using one model and related data.

Automapper different Configuration

As suggested in this answer Using Profiles in Automapper to map the same types with different logic, can anybody provide an example of using Automapper with different Configuration object?
I need to have two or more configuration for mapping between two objects. How can I register many configuration objects and how to use them?

Resources