Get nested counts in AdonisJS - count

I have the following tables:
users
(a user has many) memberships
(a membership has many) seats
(a seat has many) outcomes
I'm trying to get an outcomesCount from the user as a #computed property through an #afterFetch hook.
I've been unsuccessfully trying to get this count with a combination of withCount, withAggregate, loadCount.
Can someone help?

Related

Cypher Query - Excluding certain relationships

I am querying my graph where it has the following nodes:
Customer
Account
Fund
Stock
With the following relationships:
HAS (a customer HAS an account)
PURCHASED (an account PURCHASES a fund or stock)
HOLDS (a fund HOLDS a stock)
The query I am trying to achieve is returning all Customers that have accounts that hold Microsoft through a fund. The following is my query:
MATCH (c:Customer)-[h:HAS]->(a:Account)-[p:PURCHASED]-(f:Fund)-[holds:HOLDS]->(s:Stock {ticker: 'MSFT'})
WHERE exists((f)-[:HOLDS]->(s:Stock))
AND exists ((f:Fund)-[holds]->(s:Stock))
AND NOT exists((a:Account {account_type: 'Individual'})-[p:PURCHASED]->(s:Stock))
RETURN *
This almost gets me the desired results but I keep getting 2 relationships out of the Microsoft stock that is tied to an Individual account where I do not want those included.
Any help would be greatly appreciated!
Result:
Desired Result:
There is duplications in your query. Lines 2 and 3 are the same. Line 2 is a subgraph of Line 1. Then you are using the variables a, p and s more than once in line 1 and line 4. Below query is not tested but give it a try. Please tell me if it works for you or not.
MATCH (c:Customer)-[h:HAS]->(a:Account)-[p:PURCHASED]-(f:Fund)-[holds:HOLDS]->(s:Stock {ticker: 'MSFT'})
WHERE NOT exists((:Account{account_type: 'Individual'})-[:PURCHASED]->(:Stock))
RETURN *
It seems to me that you should just uncheck the "Connect result nodes" option in the Neo4j Browser:

DynamoDB enum input validation

Suppose, you want to create a rest api method for different car brands (BMW, AUDI, MERCEDES).
You also want to create a new car, including the car brand as property.
How can I validate if the car brand exist, before creating a new car in the table?
From the front-end, you want a dropdown list (select / option).
From the backend you want to validate the input.
What is the best practice for this?
The get car brands method will read the dynamodb table too often, creating hot partitions.
The API call to the DynamoDB table when attempting to create a new car brand would be to use a Conditional Put. That way you would say "only insert this new car brand if it does not exist already".
For the read of list of car brands, if this is something in your UI that is presented thousands of times per second, then i'd have an out of band lambda function that updates the list only when a new car brand is input (use DynamoDB Streams). I would put that list X number of items all with the same data, but different PKs. For example: pk = "CarBrandList_0" all the way through pk = "CarBrandList_5". In your code to get the car brand list, you give it the PK and a random number between 0 and 5. You have now avoided creating hot keys

Symfony2, Doctrine2, Entity Mapping

I have three tables such as A, B and C. There is ManyToMany relation from table A to table B.
At the same time Table C stores the relations between table A and B.
I want a connection between the tables. For example i want to print a data in table A which relates with table B. It's ok but when i want to take it to the next level and print a data in table A which relates with table B and which relates in table C, it doesn't consider the second condition.
That's my problem.
For better understanding
A: Tv Shows
B: Actors
C: Roles
I want to display role of an actor who acts in a certain tv show. But it returns me all roles the actor has played before (Including other tv shows). But i want the result to turn me as just one role (just one tv show)
Tv Show (1st filter) > Actor (2nd filter) > Role (Result)
Problem: I can't apply 1st filter to results.
Thanks in advance.
What you want to do is to allow the role table to act as the bridge between shows and actors.
Shows 1:many Roles many:1 Actors
So when you link Show and Actor you specify which role an actor plays for a given show. Drop the Doctrine 2 many to many relation between Show and Actor and replace with two 1:many relations with roles.
After that the queries will be easy.

Players / Teams / Matches / Seasons

I'm trying to figure out the best way to solve this 'problem'
I have 4 Custom Post Types:
Players
Teams
Matches
Seasons
And i want to connect them to each other somehow so that i can query the results in the frontend.
This is how i want them to be connected:
Each Season has many Teams
Each Team has many Players
Each Match has many Teams & Players
My first attempt was to connect these 4 types with the Relationship Field (Advanced Custom Field).
For example, in a Season's edit page there is:
Repeater Field -> Sub Field (relationship), Sub Field (Points), Sub Field (Games Played)
With the above method, I came across many problems while querying in the front end.
What would be the best method to achieve the desired results?
As per me, just prepare a new taxonomy for all these custom post types. This should be a common taxonomy is for all the four types of custom post types. Now you can relate the posts by categories of that taxonomy...Try it once

Missing values in google.com:analytics-bigquery:LondonCycleHelmet.ga_sessions_20130910

I am working with the practice repository in preparation for doing upcoming work with a large enterprise client using BQ. The repository link is: google.com:analytics-bigquery:LondonCycleHelmet.ga_sessions_20130910
I have 3 questions to ask in relation to the sample repository & a query that was run (please see the bottom of the link for the query that motivated the question:
1) What is the difference between customDimensions.index, customDimensions.value and hits.customDimensions.index, hits.customDimensions.value?
2) If a single hit has multiple custom dimensions/metrics how is that returned/queried? I only see single dimensions matching at the hit level in the sample data.
3) There are no custom metric values passed in the example data, what will those values look like?
Here is the query that motivated the previous 3 questions:
SELECT hits.page.pagePath AS urls,
hits.time,
customDimensions.index,
customDimensions.value,
hits.customMetrics.index,
hits.customMetrics.value,
trafficSource.medium,
hits.customVariables.index,
hits.customVariables.customVarName,
hits.customVariables.customVarValue
FROM [google.com:analytics-bigquery:LondonCycleHelmet.ga_sessions_20130910]
Every record in that table represents one Google Analytics Session. Big Query has this concept of nested fields and that's how individual hits are defined. They are nested into the hits record.
Answering your questions:
1) customDimensions.index and customDimensions.value are the index and value for user or session scoped custom dimensions. hits.customDimensions.index and hits.customDimensions.value re custom Dimensions set at hit scope level. The scope is defined when you create the custom Dimension through GA interface. indexes are integers from 1 to 20 (as defined in the Admin section) and value is the string passed as the value for that custom Dimension. More info about Custom Dimensions/Metrics
2) Both rows and rows.customDimensions are REPEATED RECORDS in Big Query. So in essence every row in that BQ table looks like this:
|- date
|- (....)
+- hits
|- time
+- customDimensions
|- index
|- value
But when you query the data this should be FLATTEN by default. Because it's flatten if a single hit has multiple custom dimensions and metrics it should show multiple rows, one for each.
3) Should be the same as customDimensions but the values are INTEGER instead of STRINGS.
For a simpler and more educational dataset I suggest that you create a brand new BQ table and load the data provided on this developer document page.
PS: Tell my good friends at Cardinal Path that Eduardo said Hello!

Resources