eager-loading

Unloaded “eager-loaded” properties causing issues when returning json'd data

心已入冬 提交于 2019-12-12 07:27:06
问题 Hopefully the title makes sense, I'll do my best to describe my problem. I'm currently developing an ASP.NET Web API. In my "Company" controller I have a GetCompany() action. /// <summary> /// Gets the 'Authorization-Token' request header and finds the company with the /// matching decrypted token from the database, returns it; if null, returns 404 /// </summary> /// <returns>Matching company for token passed in request or 404 if null</returns> [HttpGet][ResponseType(typeof(Company))] [Route(

virtual keyword, Include extension method, lazy loading, eager loading - how does loading related objects actually work

不问归期 提交于 2019-12-12 07:15:36
问题 Loading related object in MVC can be pretty confusing. There are lots of terms you need to be aware of and learn if you really want to know what you're doing when writing your entity model classes and controllers. A couple of questions that I've had for a very long time are: How does the virtual keyword work and when should I use it? And how does the Include extension method work and when should I use it? Here's what I'm talking about; virtual keyword: using System; using System.Collections

why isn't eager loading working in Entity Framework

雨燕双飞 提交于 2019-12-12 05:39:17
问题 I'm trying to do basic eager loading on a list of ProjectVersions where each ProjectVersion has a list of FieldValues and ChildProjects. I want the FieldValues and ChildProjects to be loaded along with all their properties when ProjectVersions is loaded, but it seems that in my code when going through each ProjectVersion, it still hits the database to get these collections (checking sql server profiler). Any pointers would be helpful. var publishedList = Repository.Find<Project>().//a bunch

Is there a way in MongoMapper to achieve similar behavior as AR's includes method?

孤街浪徒 提交于 2019-12-12 04:49:53
问题 Is there a feature equivalent in MongoMapper to this: class Model < ActiveRecord::Base belongs_to :x scope :with_x, includes(:x) end When running Model.with_x, this avoids N queries to X. Is there a similar feature in MongoMapper? 回答1: When it's a belongs_to relationship, you can turn on the identity map and run two queries, once for your main documents and then one for all the associated documents. That's the best you can do since Mongo doesn't support joins. class Comment include

Fluent Nhibernate loading not falling back on lazy loading? (grandchild entities)

不打扰是莪最后的温柔 提交于 2019-12-12 04:18:27
问题 When querying nhibernate, I'm seeing some odd behavior When I write a query like this Repository.QueryOver<Entity>() .Fetch(x => x.Child1).Eager .Fetch(x => x.child2).Eager It will eagerly grab child1 and child2 entities, but there are grandchildren for child1 and child2 that aren't lazily loaded. I'm a bit confused on how to achieve this. In my nhibernate mappings, it seems to have no affect on the laziness or eagerness of grandchildren and I require at least some entities be eagerly loaded

How to specify eager loading of associations in rails model

只愿长相守 提交于 2019-12-12 03:30:01
问题 class A < ActiveRecord::Base has_many :Bs has_many :Cs ... end I wish to load all of B's and C's whenever I do a query on A, say A.where(name: :abc) , with a single query, instead of multiple calls to database. I don't wish to specify .includes for every query I run. How do I specify eager loading in the model itself? I looked many similar question and tried do this but it does not work: default_scope :include => [:Bs, :Cs] 回答1: default_scope { includes(:Bs, :Cs) } should do it. As far as I

Triple level associations in phpactiverecord

守給你的承諾、 提交于 2019-12-12 02:55:07
问题 Right now if I try to eager load more than two objects deep in phpactiverecord, I get an error. Is something such as this: $conditions['include'] = array( 'playlists' => array('playlist_songs' =>array('song'))); User::find('first', $conditions); Just one level too much to try to retrieve? I'm getting an error Undefined offset: 0 whenever I try to use an association 3 levels deep. Thanks for any help or insight :D. Edit: So I've found a pattern that's a little odd. If I have array('playlist

Nhibernate exception when ordering entities by grandparent property when eager loading

流过昼夜 提交于 2019-12-12 01:25:18
问题 I have a data model of Country, State and City entities. Each City entity has a reference to a State, and each State has a reference to a Country (UML diagram here). This is much simplified from my actual data model. For a list of cities in the UI I am retrieving Cities from the database using Nhibernate, and I want to (1) order by the name of the Country (the grandparent entity of City), and (2) eager load the whole structure. I can get NH to do either, but not both. I get: Query specified

Eager loading not loading in rails

萝らか妹 提交于 2019-12-12 00:29:32
问题 Hi am I missing something here? I read the docs on including joins on load and tried the following below. You can see that when I use "include", the included join does not output the desired data, however when I explicitly call the join model after the fact, you can see there is the desired data. Below are my models and behavior in IRB: class Appearance < ActiveRecord::Base belongs_to :photo belongs_to :person end class Photo < ActiveRecord::Base belongs_to :event has_many :appearances, order

Laravel 5.5 - How to query notifications for follower with created_at timestamp?

左心房为你撑大大i 提交于 2019-12-11 18:35:46
问题 A user can be a follower and/or a leader. Here userA and userB (both leaders) were followed by userC (follower) at different times (see followers table below for created_at timestamp). To illustrate the issue, I will first layout the template: userX action (year) // template to understand issue below userC followed userA (2016) userA added postA/notification (2017) userC should get notification in feed, since they followed userA a year BEFORE their post userB added postB/notification (2018)