FAQ Database Discussion Community


Bookshelf js fetch withRelated option returns empty relation object

javascript,node.js,eager-loading,bookshelf.js,knex.js
I have an image model and a location model. The image model contains foreign key to location. To fetch the result I use: fetch({withRelated: ['location']}; and i recieve the following results: { "id": 24, "created_by": 1, "location_id": 202, "location": {} } But I want something like: { "id": 24, "created_by":...

Laravel5 eager loading null value

laravel-5,eager-loading
Eager loading won't work work if the field has null value. How do i escape the error Trying to get property of non-object and in model I set the relationship like this public function bilstate() { return $this->hasOne('App\Attribute', 'at_id', 'cu_bilstateid'); } can someone share the experience? Thanks...

Search within Laravel's eager loading

php,laravel-5,eager-loading
I have optional route written like this Route::get('{id}/{inid?}/{task?}', '[email protected]')->where(['id' => '[0-9]+', 'inid' => '[0-9]+']); and the controller like this public function station($id, $inid = null, $task = null) { $obj = Station::findOrFail($id); $template = 'station'; $app = array( 'docTitle' => $obj->st_name, 'lat' => $obj->st_lat, 'lng' => $obj->st_lng, 'appName' => $obj->setting->set_name,...

Laravel eager loading with nested relationship

laravel,eager-loading
I know this question has been asked but my situation is different. I have Post model with relationship to Comment model defined: /*Post Model*/ public function comments(){ return $this->hasMany('comment'); } and Comment model which each comment belong to one user : /comment model/ public function user(){ return $this->belongto('user'); } now...

custom orderBy() on constraining eager loads?

laravel,eager-loading
my question is about the possibilty of customizing Laravel's orderBy() method of the query builder, which i am using to sort an eager loaded dataset. This is the query scope I am using to generate the dataset. Everything works fine so far with this. public function scopeRestaurantsWithMenusToday($query, $city_uri){ return $query->where('city_uri',...

Getting Count() of navigation property without loading whole collection in Entity Framework

c#,entity-framework,xaml,eager-loading,navigation-properties
In XAML DataGrid is bound to a list of EF entities called Results. One of columns is bound to Count of Buildings navigation property. Lazy loading is off. So I need to include Buildings in query, to get it's count. This causes a performance issues because whole Buildings entity collection...

Laravel Eager with Where constraint

php,blade,eager-loading,laravel-5
I have 2 methods with eager loading and paginate. but problem is that i have to use where constraint too and i am getting offset 0 error. public function showAllOrders(){ $orders = \admin\Order::with('orderfiles','paymentStatus','orderStatus','orderDelivery','flexibleDelivery')->paginate(20); return View('admin.all_orders') ->with('orders',$orders); } public function showAllPaidOrders(){ $orders = \admin\Order::with(array('orderfiles','orderStatus','orderDelivery','flexibleDelivery','paymentStatus'=>function($query){...

How do I filter on eagerly-loaded tables in Eloquent?

php,laravel,eloquent,eager-loading
Basically, I want to be able to retrieve users and eagerly load e-mail addresses, and then restrict which users I bring in with a where clause. $query = User::with('emails')->whereIn ('user_id', $user_ids); $query->where('emails.email_address', 'LIKE', "%example%"); $usersWithEmails = $query->get(); This works: $query->where('first_name', 'LIKE', "%test%"); which leads me to believe that the where...

conditions in eager loading in eloquent laravel

php,laravel,eloquent,eager-loading
I get my Product be this code. I use with() method to load variations relation. I have some filters for it. But if any variations does't exist I get Product. How can I get only this Product where variations exist ? $query = Product::with(array( 'variations' => function($query) use($filters){ if(isset($filters['price_start']) &&...

Nested Eager Loading with Joins in Laravel

eloquent,laravel-5,eager-loading
I have the following Tables and their relationships products Table: id product_name product_price 1 Product A 2 USD 2 Product B 3 USD components Table id component_name component_price 1 Component A 5 USD 2 Component B 3 USD product_component Pivot Table id component_id product_id 1 1 1 2 1 2...

Is there a way to Include() all with dbcontext?

c#,asp.net-mvc,entity-framework,dbcontext,eager-loading
When querying a DbContext with eager loading, it is required to Include("Navigation") in order to populate Navigation Properties. However on some occasions I would like to simply Include all navigation properties for an entity. Is there a method for this, or a way to do it? I'm assuming you could...

Laravel eager loading sort by relationship

php,laravel,laravel-5,eager-loading
I have some relationships (that i can hopefully explain correctly) and need to sort the output by what is essentially a distant relation. I have a pivot table that contains details for many of the relations, including that that i want to sort by. --User.php public function players() { return...

Laravel eager loading with field limit

laravel-5,eager-loading
I have three tables: users id name role_id password ... role_user id role_id user_id roles id name slug ... Now I want to get a user list with users.id,users.name, roles.id. That's my code: $query = User::with(['roles'=>function($q){ $q->lists('role_id'); }])->get(['id','name']); the response like that { "id": "1", "name": "aaaa", "roles": [] },...

Sequelize.js many to many eager loading

database,node.js,many-to-many,sequelize.js,eager-loading
I have 2 models: User and Team There are multiple kinds of users (in this case Mentors and Moderators) which are differentiated using an attribute in the User model(). The associations between User and Team are as below: User.hasMany(models.Team, {as: 'Mentors', through: models.TeamMentor, foreignKey: 'mentorId'}); User.hasMany(models.Team, {as: 'Moderators', through: models.TeamModerator,...