How to remove nested duplicate relations from swagger in Loopback4 - swagger-ui

Some of endpoints have requestBody which have so many nested relations. When i opened this endpoint in /explorer, page is freezing completely and loading over 5 minutes. I wanted to remove this relations and i used includeRelations options as false but i need some relations in reqBody. I want to clear just nested duplicate relations from openapi.json??
Related stackoverflow question but answer is not enough for my situation

Related

mongoid splits nested attributes in two hashes?

I've got a model List with nested attributes from another one, Article. What bugs me is I have Ruby request params having my first nested attribute in Article hash, and all the others(2nd,3rd article data, etc) in article_parameters.
I follow the standard mongoid tutorial here.
I have #list.articles.build in create method of List controller.
Can I influence what goes into build method? I've tried to call build(all_the_correct_hashes) but it does not seem to fix the issue.
So, in the nutshell I have 2 questions.
why articles gets only the first nested attribute, 2nd and next go to article_parameters hash?
why list.articles.build only creates _id in my Mongo document, but does not populate it with other fields?
I'll write up my solution, since I see people upvoting my question.
Frankly, I did not find any answer as to why such behaviour occurs.
The solution is a bit hackish.
In your save controller, call List.article.build(id => params[:id], someotherstuff => params[:someotherstuff])
Everything you pass to build in this case will populate article_parameters hash.
id and sometherstuff are fields of my Article model.
I feel this should be done implicitly by Mongoid, but it just does not work. Their development does not see anything wrong with it, either.

"Unpermitted parameter:" error in Two Many-To-Many association with nested attributes added to whitelist already

I'm taking my first steps "on rails". I looked up several questions on stackoverflow and used google A LOT, but still I can't seem to solve my problem.
I´m trying to write a rails app that lets you manage a list of movies, and a list of actors. Movies can have multiple actors (and hence an actor can star in multiple movies).I have two models Movie and Actor as well as the joint ActorsMovie model. As you can see, I want to establish a Two Many-To-Many relationship.
Please find the relevant files here:
https://gist.github.com/ecksma/f09d2a6ec631e46eafe9
Even though I added params.require(:movie).permit(:title, :year, actors_attributes:[:actor_id,:name] ) to movies_controller, I get an Unpermitted parameter: actors error when I try to create a new movie with an actor.
Command line output
https://gist.github.com/ecksma/f09d2a6ec631e46eafe9#file-command_line_output
I have the same problem when I try to create a new actor with movies. The actor is created but I get Unpermitted parameter: movies, although I added params.require(:actor).permit(:name, movies_attributes:[:title,:year,:movie_id]) to actors_controller.
Forms and basic CRUD seems to work, except that I can't seem to hook up movies with actors and vice versa.
Any suggestions on what I´m doing wrong?
Did you try to add accepts_nested_attributes_for :actors in Movie model?

Model relationship in rails and their handling

I have a requirement for an app where two models invoice and message needs to be linked. The link/relationship should be able to do following things:
The invoice should be able to store the message_id.
The message should also be able to store the invoice_id - a foreign key to the invoice table.
There are some extra fields in both models.
Also can you tell me how will i be able to generate a form_for for this kind of models, where two models get data at the same time but of different fields. Should i use hidden_fields?
Please Help.
Here You will learn about has_one and belong_to associations, which can be used with table structure You are searching for (though without extra explanation it sounds odd).
http://guides.rubyonrails.org/association_basics.html#the-belongs-to-association
http://guides.rubyonrails.org/association_basics.html#the-has-one-association
After linking You models check nested attributes Railscasts to get and idea how You can construct form for multiple elements with mass-assignment supported:
http://railscasts.com/episodes/196-nested-model-form-part-1
http://railscasts.com/episodes/197-nested-model-form-part-2

Rails blog and post linking

I have a rails app that works almost like a blog, and I use a tagging system to categorize the posts.
I need to add to some of the posts something similar to a "related posts" feature.
So for example if post 1 is related to post 4, at the end of the show action for post one I want to render an image of post 4 and at the same time at the end of post 4 an image of post 1.
My idea is to create a "link" model that has a HABTM relations with the post model, but I'm not sure if a "post" has many "links" trough "linkings" would be better.
Both of the ideas seem to have the same result, so which approach should I prefer?
HABTM is by nature very simple, with just a table of foreign key pairs joining models.
Typically has_many through is used when you need to add additional attributes to that join relation, and/or when you need to treat the joins as their own model.
In your case, for example, you might want the links to appear in the order that they were created. For this to happen you'd need to store the create timestamp on the relationship. For this, the simple HABTM join table is not enough, so you switch to has_many through and create a Linking model to encapsulate the join.
To continue the example, you might also make Linking a first-class resource, and have a page where you can edit/add/remove them separately from either linked Post.
Personally I've always used has_many through in the majority of cases. It just feels cleaner to me (no auto-naming table magic to accept or override, and the linking is more visible), and I find that very often, join relationships do deserve to be first class citizens.

What is the rails way of rendering groups of data

My model can be described as following:
One Forum has many Threads. One Thread has many Comments.
Data is not denormalized; i.e. Threads has FK only leading to Forum and Comments has FK leading only to Thread.
What will be "The Rails Way" of selecting specific Threads and then rendering Comments in a template grouped by the thread they belong to?
Read Active Record Associations here.
Define has_many and belongs_torelationships for your Forum<> Thread and Thread<>Comment
Querying using rails interface would be quite easy for you then. Refer here
Selecting commnets of specific threads(grouped by it)
Comment.where('thread_id in ?',[specific_thread_ids_to_search]).order('thread_ids')

Resources