Directus CMS: How to display cardinality count like in the admin using api endpoint - content-management-system

In the admin page of your Directus CMS you can see, when using a M2M and related O2M relation the number of records in the relation. I would like to display, using vuejs, that cardinality next to the category field and hide the categories with no relation yet.
Any idea on this ?

Well,
It looks as it goes like this
https://api........./items/blog_categories?meta=total_count&result_count&fields=*.*
So nothing more...and the meta can be omitted as it won't matter in the context of my question.

Related

Reverse relationships in Prismic

Suppose I have a simple blog with the data type of Article and the data type of ArticleTag:
Article ->
title - Title field
tag - Content relationship to ArticleTag
ArticleTag ->
title - Title field
icon - Text field
For that purpose, I would like to return query all ArticleTags and get each with N Articles (or even all of them), but the API documentation (both GraphQL and REST) is awfully silent on how to expand reverse content relationships. i.e. they only specify how to get fields from ArticleTag per Article (or how to get all Articles with a specific ArticleTag per id which is strange but whatever)
I can think of a workaround: query all tags, then for each tag query all articles. Thing is that this sounds awfully slow as it generates N+1 API requests for the number of tags I have, plus, this may be happening on the client-side as well in this project! So I'd rather avoid that if in any way possible.
Yeah the workaround you presented is the only way to do that.

Json-ld schema for brand page?

I am trying to understand how to define schema Brand on a brand page.
Using the example of a website selling shoes, apart from category pages, there will be brand pages listing all products (they link out to their respective product page) of the respective brand. So, at a high level what I figure will be an approach like this:
- schema: CollectionPage, defining the WebPage
- schema: Brand, connected to CollectionPage using `mainEntityOfPage`
- schema: ItemList, list of the brand's products displayed
In the above, I am not able to connect the ItemList to Brand, so it's hanging (Google SDTT is showing 2 independent schemas on the page).
There's another option, where we connect the ItemList to CollectionPage using mainEntityOfPage but then Brand will be hanging.
Is there some way to connect all the 3 schemas?
If not, are there alternate methods of defining the 3 things so that we can connect them?
A point to note here is that both Brand and ItemList has name property and they hold the same values, but that doesn't connect them, as I understand.
Any insight into this will help.
use these combinations
Brand/subjectOf/WebPage
Product/brand/Brand
ItemList/itemListElement/Product
linked using the relevant #id

One URL, which can display one of two Wicket pages based on database content

I want to achieve the following using Apache Wicket.
We have the requirement that the URL /xxxx can display one of two things.
If there is an entry in the "city" table (column "url_name") then we should display the CityDetailPage.
If there is an entry in the "venue" table (column "url_name") then we should display the VenueDetailPage.
These are quite distinct pages, with hundreds of lines of various wicket components and so on.
Currently we had two different URLs (/city/xxx and /venue/xxx) and they were mapped in the application, and that worked fine. Now they should share a URL.
I need to have some kind of logic like "select id from city where url_name=?" and if there is a row display the CityDetailPage, else if "select id from venue where url_name=?" then VenueDetailPage, otherwise 404.
Things I've considered:
Have one huge page with two sections which are visible/invisible based on what's found. But that's quite inelegant, these are two different pages basically.
Have a Servlet which looks at the path and does the db query then an internal redirect (we have Apache in front of our Servlet engine). Also feels inelegant, it's outside wicket.
Maybe some Page which does nothing more than some kind of wicket exception which displays another page (but does not alter the URL), not sure which type to use?
Thanks in advance! I am quite stuck :(
I'd recommend to use custom IProvider, i.e. instead of mountPage("the/path", VenuePage.class) do mount(new MountedMapper("the/path", new MyClassProvider())), where MyClassProvider implements IProvider and returns different page class in #get() depending on your conditions.

Parse DB Design: How to get all the posts for particular category

I'm creating a discussion system using Parse.com
In my [simplified] system, there are Posts, Categorys, and Comments.
As you probably imagined, Posts can belong to one or more Categorys and can have multiple Comments.
However, often users will want to see all the Posts in a Category. If I set up my database like this
Post (name, content, categories)
Category(name)
I am worried that querying for all the Posts in a Category will be very ineffeficient (since it will have to check the categories field of every Post.
However, if I design the database like
Post (name, content)
Category(name, posts)
it will be inefficient for me to query what Categorys a Post belongs to since it will have to search all the Posts arrays in the all the Categorys.
I'm sure this must be a common Database design dilemma but I am still new at this. What is the best way to approach and solve this problem?
What you're looking for is a bi-directional, many-to-many relationship between Post and Category. With Parse, there are at least three approaches you can take.
You can add a column as a PFRelation to the Post table. You can ask a Post for its categories relation, create a query from that and run it. Inversely, if you have a category you can create a Post query with a where clause on the categories key. PFRelations are good if you will have big collections.
If you think better as a relational model, just create a "join" table called CategoryPosts. It would have two pointer columns, one for the Post and another for the Category. This is also very efficient.
Lastly, you could add an array column to either class. Since all of the results are loaded at once, this works best for smaller collections.
These options are described in a little more detail in the Parse Relations Documentation.

Is it possible to group multiple collections in mongodb

so I'm working with a database that has multiple collections and some of the data overlaps in the collection . In particular I have a collection called app-launches which contains a field called userId and one called users where the _id of a particular object is actually the same as the userId in app-launches. Is it possible to group the two collections together so I can analyze the data? Or maybe match the the userId in app-launches with the _id in users?
There is no definit answer for your question Jeffrey and none of the experts here can tell you to choose which technique over other just by having this information.
After going through various web pages over internet and mongo documentation and understanding the design patterns used in Mongo over a period of time, How I would design it depends on few things which I can try explaining it here in short.
if you have a One-To-One relation then always prefer to choose Embedding over Linking. e.g. User and its address (assuming user has only one address) thus you can utilize the atomicity (without worrying about transactions) as well easily fetch the records without too and fro to bring other information as in the case of Linking (like in DBRef)
If you have One-To-Many relation then you need to consider whether you can do the stuff by using Embedding (prefer this as explained the benefits in point 1). However, embedding would help you if you always want the information altogether e.g. Post/Comments where your requirement is to get the post and all of its comments by postId let say. But think of a situation where you need to get all the comments (and it related posts) which contains some specific tags in comments. in this case you should prefer Linking Because if you go via Embedding route then you would end up getting all the collection of comments for a post and you have to filter the desired comments.
for a Many-To-Many relations I would prefer two separate entities as well another collection for linking them e.g. Product-Category.
-$