-
Notifications
You must be signed in to change notification settings - Fork 27
$select should only have effect on primary entity #255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi, thanks for the detailed report! I wasn't able to reproduce this behaviour where the Using the request {
"@context": "http://localhost:8000/odata/$metadata#People(id,tags())",
"value": [
{
"id": 1,
"tags": []
},
{
"id": 2,
"tags": [
{
"id": 3,
"name": "c"
},
{
"id": 4,
"name": "d"
}
]
}
]
} Is there more information on your setup you could share? |
@27pchrisl wahou, i'm really sorry.
class People extends Model
{
protected $table = 'peoples';
use HasFactory;
#[LodataRelationship]
public function link(){
return $this->belongsTo(Link::class, 'link_id');
}
#[LodataRelationship]
public function tags(){
return $this->belongsToMany(Tag::class);
}
}
class Tag extends Model
{
use HasFactory;
}
class Link extends Model
{
use HasFactory;
} Schema::create('peoples', function (Blueprint $table) {
$table->id();
$table->string('lastna
8000
me');
$table->unsignedBigInteger('link_id');
$table->timestamps();
$table->foreign('link_id')->references('id')->on('links');
}); {
"@context": "http://localhost/odata/$metadata#People(id,link(),tags())",
"value": [
{
"id": 1,
"link": {
"id": 1
},
"tags": [
{
"id": 1,
"name": "eveniet",
"created_at": "2022-05-10T20:35:40+00:00",
"updated_at": "2022-05-10T20:35:40+00:00"
},
{
"id": 2,
"name": "et",
"created_at": "2022-05-10T20:35:40+00:00",
"updated_at": "2022-05-10T20:35:40+00:00"
},
{
"id": 3,
"name": "fugit",
"created_at": "2022-05-10T20:35:40+00:00",
"updated_at": "2022-05-10T20:35:40+00:00"
}
]
},
} we can see in this example that the link does not contains the correct fields.... with my corrections we have the correct result {
"@context": "http://localhost/odata/$metadata#People(id,link(),tags())",
"value": [
{
"id": 1,
"link": {
"id": 1,
"value": "asperiores",
"created_at": "2022-05-10T20:35:45+00:00",
"updated_at": "2022-05-10T20:35:45+00:00"
},
"tags": [
{
"id": 1,
"name": "eveniet",
"created_at": "2022-05-10T20:35:40+00:00",
"updated_at": "2022-05-10T20:35:40+00:00"
},
{
"id": 2,
"name": "et",
"created_at": "2022-05-10T20:35:40+00:00",
"updated_at": "2022-05-10T20:35:40+00:00"
},
{
"id": 3,
"name": "fugit",
"created_at": "2022-05-10T20:35:40+00:00",
"updated_at": "2022-05-10T20:35:40+00:00"
}
]
},
} |
But i realize now that my correction is not correct. The more i think about it the more it feels that (sorry if i'm wrong and seems saying bad things ) the way navigation properties are handle is not correct. I think it could be due to the way you handle properties of navigation properties in this case Line 258 in 7f9ce1c
shouldEmit with the context of the primary EntitySet (People) but should in reality be called with it's own EntitySet context ( Link ) .
a good example would be to use this request In the other case (but it should certainly be in another thread), we can see that the owner of the properties is "always" lost and we assume that it's always the primary EntitySet lodata/src/Expression/Parser.php Lines 752 to 758 in 7f9ce1c
|
Hi @Angelinsky7, thanks for the detailed issue report! There seems to be a common element to these reports, that effectively when using query parameters with For expansion Lodata creates a sub-request with all the parameters provided for expansion, but when Lodata looked for a set of transaction parameters to use this sub-transaction was not being correctly attached, which meant the upstream or main transaction was being used. Could you install flat3/lodata:5.x-dev and see if this issue is fixed? |
Context
Db
Request
http://localhost:8080/odata/Person?$select=id$expand=tags
Result
Expected result
Only with this request :
http://localhost:8080/odata/Person?$select=id$expand=tags($select=id)
we should have the actual result.Proposal
Iv'e made some test and it seems that with this commit things are working correctly for simple cases : Angelinsky7@985118e but because i don't have a correct knowledge of out work it's difficult to see if it's the correct way of resolving this issue.
Version
"flat3/lodata": "^5.11"
The text was updated successfully, but these errors were encountered: