Comments (11)
The latest release adds support for your relationship with 'supplies[]->supply->id'
.
from eloquent-json-relations.
Thanks, this is indeed a bug. The latest release fixes it.
from eloquent-json-relations.
There are multiple issues:
- The syntax is not correct: It's
'supplies[]->...'
, not'supplies->[]->...'
. - A relationship can't have the same name as an attribute.
- This kind of nested path not supported (yet). This would work:
'supplies[]->supply_id'
from eloquent-json-relations.
I changed these issues and it still doesn't work.
public function test() {
return $this->belongsToJson('App\Supply', 'supplies[]->supply_id');
}
Its giving error when i try call this:
`$stocks = StockControl::with('destination')->whereHas('test', function($query) use ($supplies) {
$query->whereIn('id', $supplies);
});
Error:
SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for integer: "supply_id" (SQL: select count(*) as aggregate from "stock_control" where exists (select * from "supplies" where ("stock_control"."supplies")::jsonb @> jsonb_build_array(jsonb_build_object(1::text, "supplies"."id")) and "id" in (2, 3, supply_id)) and exists (select * from "stock_entry" where "stock_control"."id" = ("stock_entry"."stock_control_id")::int and "destination_id" in (1, 2)) and exists (select * from "stock_exit" where "stock_control"."id" = ("stock_exit"."stock_control_id")::int and "origin_id" in (1, 2)) and exists (select * from "stock_requisition" where "stock_control"."id" = ("stock_requisition"."stock_control_id")::int and ("destination_id" in (1, 2) or "origin_id" in (1, 2))) and exists (select * from "stock_transference" where "stock_control"."id" = ("stock_transference"."stock_control_id")::int and ("destination_id" in (1, 2) or "origin_id" in (1, 2))))
from eloquent-json-relations.
Hello,
the error was solved, but when I try to get the related items its return an empty array.
return StockControl::first()->items;
public function items()
{
return $this->belongsToJson('App\Supply', 'supplies[]->supply_id');
}
from eloquent-json-relations.
What's the result of dd(StockControl::first()->supplies);
?
from eloquent-json-relations.
array:1 [▼
0 => array:4 [▼
"supply" => array:16 [▼
"id" => 2
"name" => "Alfinete cabeça colorida [50 unidades]"
"unit" => "CX"
"brand" => array:4 [▶]
"group" => array:5 [▶]
"bar_code" => null
"brand_id" => 3
"group_id" => 3
"supplier" => null
"created_at" => "2019-01-28 11:37:23"
"updated_at" => "2019-01-28 11:37:23"
"ideal_stock" => null
"manufacturer" => array:4 [▶]
"maximal_stock" => null
"minimal_stock" => null
"manufacturer_id" => 3
]
"ordered" => "10"
"quantity" => 2
"max_quantity" => 0
]
]
from eloquent-json-relations.
Your JSON data has to match the new selector:
[
{
"supply_id": 1,
},
{
"supply_id": 2,
}
]
from eloquent-json-relations.
So I can't access the property id inside object supply? Because it's in production and I can't change the structure.
from eloquent-json-relations.
No, this is not possible at the moment. I will check whether it's possible to support that.
from eloquent-json-relations.
Ok, thanks for helping!
from eloquent-json-relations.
Related Issues (20)
- pivot always return the same data on belongsToJson HOT 3
- Support for filtering by pivot value? HOT 5
- Support for custom key HOT 1
- BelongsToJson returns wrong results HOT 2
- hasMany - belongsToJson - hasManyJson HOT 4
- Artisan model:show failed HOT 1
- Need a basic Understanding for a json_encoded column HOT 6
- getAttribute() conflict HOT 1
- SqliteGrammar / Sqlite support HOT 11
- laravel compoships HOT 4
- Defining Json Relation in factory definition HOT 3
- Not an issue, really need a help HOT 2
- Nested Array of Objects throws array_key_exists(): Argument #2 ($array) must be of type array, null given HOT 2
- has and WhereHas doesn't work HOT 1
- One dimensional array HOT 5
- MySQL MEMBER OF () performance improvements HOT 5
- Is it possible to define a relationship using a key that can be nested at variable depths? HOT 14
- Great Package HOT 1
- String values fail for belongsToJson and HasManyJson HOT 4
- Many To Many Eager Loading Breaks with array_key_exists(): Argument #2 ($array) must be of type array, null given HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eloquent-json-relations.