I am in a situation where I want to get the form for each team of based on competition
Team model
public function standing()
{
return $this->hasMany(Standing::class);;
}
Competition model
public function standing()
{
return $this->hasMany(Standing::class);;
}
Each Team has many Standing
Each Competition has many Standing
standing table
team_id
competition_id
form
my code
$f = Fixture::where('status', 'NS')
->with('teamA', 'teamB', 'competition')
->get();
since all fixtures of all competitions are coming, but once team can be in two competition,
hence its form is different.
[
{
"name": "Leicester vs Newcastle",
"team_a": {
"id": 10,
"name": "Leicester",
**"form": null**
},
"team_b": {
"id": 2,
"name": "Newcastle",
**"form": null**
},
"competition_id": 1,
"competition": {
"id": 1,
"name": "Premier League",
},
},
{
"name": "Leeds vs Tottenham",
"id": 344,
"team_a": {
"id": 19,
"name": "Leeds",
"form": null
},
"team_b": {
"id": 11,
"form": null
},
"competition_id": 2,
"competition": {
"id": 1,
"name": "Other League",
},
},
]
I have tried to explain the situation,
can someone please tell me how to get this?
for ex.
in champions league(competition), man. united has form WWWLDW, but same team in another league might be different
Related
I have two tables, users and like_categories which has many-to-many relationship. The pivot table is called like_category_user. After inserting two users data into the db, here is my pivot table look like:
https://i.imgur.com/MeeRbiV.png
Im a little bit confused on how can i access the pivot table since I didnt create a custom model for that pivot table. I want to count the amount for each of the different like category for each user and store it in object array like this:
[
{
"User Id": 1,
"Like Categories": [
{
"Category": Chinese Restaurant
"Amount": 1
},
{
"Category": Korean Restaurant
"Amount": 2
},
{
"Category": Fast Food Restaurant
"Amount": 3
},
{
"Category": Italian Restaurant
"Amount": 1
},
{
"Category": Steakhouse Restaurant
"Amount": 3
}
]
},
{
"User Id": 2,
"Like Categories": [
{
"Category": Thai Restaurant
"Amount": 1
},
{
"Category": Kebab Shop
"Amount": 3
},
{
"Category": Pizza Place
"Amount": 2
},
{
"Category": Steakhouse
"Amount": 1
}
}
}
]
My process method:
public function showUserLikesData() {
//
}
Try following this explanation, according to your code.
There is no real need to create a model for this table. Basically you will need to create a function in your models to have access to this table.
In your view's or your api, you will need to mention this function along with Pivot, but the field. Something like:
$showUserLikesData->pivot->FieldName
In your relationship you can add ->withPivot('column_name'), which allows you to use more than foreign keys from the pivot table. So, an example:
public function things(){
return $this->belongsToMany('App\ModelName')->withPivot('column_name')->withTimestamps();
}
I have a query in aws cloudsearch. I did the following things
1) Created domain
2) uploaded the data & created indexing
I have data fields like : user_id, user_name, user_details, etc
My objective is to get the grouped/distinct data of particular field & its total count. In Cloudsearch Group by / Distinct key words not supported. So, I went through the cloudsearch documentation & done it by adding facet.user_id={} in my query string.
But I need user_name field data along with user_id and count.** Please update me regarding this.
Here is my full query : ?q="Tamil Selvan"&facet.user_id={}
Here is my query result :
{
"status": {
"rid": "isTcmOYp+AEKhpbc",
"time-ms": 6
},
"hits": {
"found": 986,
"start": 0,
"hit": []
},
"facets": {
"user_id": {
"buckets": [{
"value": "5",
"count": 213
}, {
"value": "182",
"count": 197
}]
}
}
}
My expected result :
{
"status": {
"rid": "isTcmOYp+AEKhpbc",
"time-ms": 6
},
"hits": {
"found": 986,
"start": 0,
"hit": []
},
"facets": {
"user_id": {
"buckets": [{
"value": "5",
"user_name":"Tamil Selvan",
"count": 213
}, {
"value": "182",
"user_name":"Tamil Selvi",
"count": 197
}]
}
}
}
The proper solution would be to look up the user_names for the user_id facet values from your datastore (which CloudSearch is not, or at least should not be).
CloudSearch is a search solution; you shouldn't be trying to ask it which user_name belongs to some user_id, as that's a question for your data store.
I need to update my code to include Media, which is oneToMany unidirectional mapped in Object.php Entity. Ideally I need my code to return all objects even though without media, currently it only returns objects WITH media but it returns multiple results if there are multiple media items.
If you think I refactor the code and use something much simpler, than let me know - I didn't find a way to get the feed using the getRepo() and findBy() functions (no serialization?)
Here's my code:
// Build object QB
$emObject = $this->objectService->getManager();
$qbObject = $emObject->createQueryBuilder();
$qbObject->addSelect(['o.id', 'o.title', 'o.description', 'm as multimedia', 'c.id as category_id', 'c.name as category_name'])
->from('Application\Entity\Cms\Object', 'o')
->leftJoin('Application\Entity\Cms\Media', 'm', 'WITH', '1 = 1')
->leftJoin('o.media', 'om')
->leftJoin('Application\Entity\Cms\Category', 'c', 'WITH', '1 = 1')
->leftJoin('o.category', 'oc')
->andWhere('om.id = m.id')
->andWhere('oc.id = c.id')
->andWhere('o.member = :member')
->setParameter('member', $member);
$objectList = $qbObject->getQuery()->getResult(Query::HYDRATE_ARRAY);
$viewModel->setVariables(['object' => $objectList]);
return $viewModel;
Which returns:
{
"object": [
{
"multimedia": {
"id": 22,
"title": null,
"url": "\/srv\/pois\/cms\/e9049aaac93ce96c81e16340027a804b.png"
},
"id": 34,
"title": "imgTest",
"description": "f",
"category_id": 1,
"category_name": "Chambres"
},
{
"multimedia": {
"id": 23,
"title": null,
"url": "\/srv\/pois\/cms\/ce0c7d669c567369485a01c65197943f.png"
},
"id": 34,
"title": "imgTest",
"description": "f",
"category_id": 1,
"category_name": "Chambres"
}
]
}
However, I need the multimedia objects to be in one array and only return 1 object, like:
{
"object": [
{
"multimedia": {
1: {
"id": 22,
"title": null,
"url": "\/srv\/pois\/cms\/e9049aaac93ce96c81e16340027a804b.png"
},
0: {
"id": 23,
"title": null,
"url": "\/srv\/pois\/cms\/ce0c7d669c567369485a01c65197943f.png"
},
}
"id": 34,
"title": "imgTest",
"description": "f",
"category_id": 1,
"category_name": "Chambres"
}
]
}
I always work with DQL queries without QueryBuilder. I think this is what you want:
$query = $this->entityManager->createQuery(
"SELECT o, m FROM 'Application\Entity\Cms\Object' o JOIN o.multimedia m WHERE o.member = :member"
);
$query->setParameters(array('member' => $member));
$objects = $query->getResult();
I don't think it is more complicated than that.
In QueryBuilder it probably looks like this:
$qb = $this->entityManager->createQueryBuilder();
$qb->select('o', 'm')
->from('Application\Entity\Cms\Object', 'o')
->leftJoin('o.multimedia', 'm')
->where('o.member = :member')
->setParameter('member', $member);
return $qb->getQuery()->getResult();
Please come back with details if this doesn't return what you want. I might be able to help out to get what you want.
I am trying to integrate the bryntum component(schedule) in php. I am not much aware in ext js.
Please see the images here
Here, Name fields are fetching properly, whereas Capacity is not accessing. These values are coming from Zoho CRM.
My code is like Click, whereas r-read.php file is the responsible file for fetching the record from CRM and store it in a json format. It is like
{
"success": true,
"total": 9,
"root": [{
"Id": 1,
"Name": "Sri Test",
"Capicity": "190.0"
}, {
"Id": 2,
"Name": "tester_test01",
"Capicity": "500.0"
}, {
"Id": 3,
"Name": "Tesing room 23",
"Capicity": "5000.0"
}, {
"Id": 4,
"Name": "Test for 6th product",
"Capicity": "5000.0"
}, {
"Id": 5,
"Name": "Banquet hall test-01",
"Capicity": "500.0"
}, {
"Id": 6,
"Name": "test room",
"Capicity": "1000.0"
}, {
"Id": 7,
"Name": "Grande Ballroom",
"Capicity": "4000.0"
}, {
"Id": 8,
"Name": "Cedar Room",
"Capicity": "1400.0"
}, {
"Id": 9,
"Name": "Maple Room",
"Capicity": "1200.0"
}]
}
In the capacity column, it will show like 190.0 , 500.0, 5000.0 etc like Name column.
I'm not familier with the Bryntum schedular component, but most of the time when you have problems like these it's because you didn't define the Capacity field in your model.
I saw you used the following model: Sch.model.Resource. Can it be that is only has the Name field and not Capacity? Your JSON response looks fine to me.
In the sample JSON above, Capacity is spelled Capicity.
See if the same spelling needs can be used everywhere. Maybe then the data will resolve properly.
Recently, our team is going to develop mobile(iphone, android platforms) applications for our existing website, let user can use the application to more easy to read our content via the application.
But our team have different views in JSON schema of the API return, below are the sample response.
Schema type 1:
{
"success": 1,
"response": {
"threads": [
{
"thread_id": 9999,
"title": "Topic haha",
"content": "blah blah blah",
"category": {
"category_id": 100,
"category_name": "Chat Room",
"category_permalink": "http://sample.com/category/100"
},
"user": {
"user_id": 1,
"name": "Hello World",
"email": "helloworld#hello.com",
"user_permalink": "http://sample.com/user/Hello_World"
},
"post_ts": "2012-12-01 18:16:00T0800"
},
{
"thread_id": 9998,
"title": "asdasdsad ",
"content": "dsfdsfdsfds dsfdsf ds",
"category": {
"category_id": 101,
"category_name": "Chat Room 2",
"category_permalink": "http://sample.com/category/101"
},
"user": {
"user_id": 2,
"name": "Hello baby",
"email": "hellobaby#hello.com",
"user_permalink": "http://sample.com/user/2"
},
"post_ts": "2012-12-01 18:15:00T0800"
}
]
}
}
Schema type 2:
{
"success": 1,
"response": {
"threads": [
{
"thread_id": 9999,
"title": "Topic haha",
"content": "blah blah blah",
"category": 100,
"user": 1,
"post_ts": "2012-12-01 18:16:00T0800"
},
{
"thread_id": 9998,
"title": "asdasdsad ",
"content": "dsfdsfdsfds dsfdsf ds",
"category": 101,
"user": 2,
"post_ts": "2012-12-01 18:15:00T0800"
}
],
"category": [
{
"category_id": 100,
"category_name": "Chat Room",
"category_permalink": "http://sample.com/category/100"
},
{
"category_id": 101,
"category_name": "Chat Room 2",
"category_permalink": "http://sample.com/category/101"
}
],
"user": [
{
"user_id": 1,
"name": "Hello World",
"email": "helloworld#hello.com",
"user_permalink": "http://sample.com/user/Hello_World"
},
{
"user_id": 2,
"name": "Hello baby",
"email": "hellobaby#hello.com",
"user_permalink": "http://sample.com/user/Hello_baby"
}
]
}
}
Some Developers claim that if using schema type 2,
can reduce data size if the category & user entities comes too much duplicated. it does really reduce at least 20~40% size of response plain text.
once if the data size come less, in parsing it to JSON object, the memory get less
categoey & user can be store in hash-map, easy to reuse
reduce the overhead on retrieving data
I have no idea on it if schema type 2 does really enhanced. Because I read so many API documentation, never seen this type of schema design. For me, it looks like a relational database. So I have few questions, because I have no experience on designing a web services API.
Does it against API design principle (Easy to read, Easy to use) ?
Does it really get faster and get less memory resource on parsing on IOS / Android platform?
Does it can reduce the overhead between client & server?
Thanks you.
When I do such an application for android, I parse JSON just one and put it in database. Later I'm using ContentProvider to access it. In Your case You could use 2nd schema but without user, category part. Use lazy loading instead but it will be good solution just in case categories and users repeat often.