Questions tagged [eager-loading]

Eager loading is a way to load objects of a certain class and a number of named associations in the same request.

When you load records from the database and also want to access the associated objects for each of these records, it’s a good idea to make use of eager loading. Eager loading reduces the amount of queries made to the database and therefore increases performance.

This is one of the easiest ways of to prevent the dreaded 1+N problem in which fetching 100 posts that each need to display their author triggers 101 database queries. Through the use of eager loading, the 101 queries can be reduced to 2.

# Rails 2
Blogpost.all(:include => :comments)

# Rails 3
Blogpost.includes(:comments).all

# Entity Framework
Blogpost.Include(bp => bp.Comments);
1515 questions
0
votes
1 answer

Rails app crashes when config.eager_load = true

I have an app that successfully builds on my local system, but when deployed to Heroku, or run with rails server -e production yields: => Rails 4.0.0 application starting in production on http://0.0.0.0:3000 => Run `rails server -h` for more startup…
0
votes
0 answers

Hibernate parent-child @OneToMany relationship with default Eager fetch

I have the next class: @Entity public class Task{ @OneToMany(mappedBy = "parent") private Set childs; @ManyToOne(cascade = CascadeType.MERGE) private Task parent; } Which by default has Eager loading if I'm not wrong, the…
KBorja
  • 257
  • 1
  • 5
  • 15
0
votes
1 answer

Missing Information When Eager Loading With Entity Framework

When trying to eager load the PriceGridRow, the index and value properties of PriceGridColumn are populated but the Id and the ProduceGridRowId are not. If i try to explicitly include PriceGridColumns it get duplicate columns (ie. i have 10 columns…
Kelly
  • 15
  • 2
0
votes
1 answer

How to load at once all objects related to specified in SQLAlchemy?

This is simplified project of my database. My model is created by SQLAlchemy and it looks like this #!/usr/bin/python class Book(Base): id = Column(Integer, primary_key = True) title = Column(Unicode(512)) sentenses =…
noisy
  • 6,495
  • 10
  • 50
  • 92
0
votes
2 answers

Cant add Includes (eager-loading) to correct place

I'm trying to speed up some of my db tier functions by adding the proper Include statements to force eager loading and reduce the number of queries I make to the database. However in 90% of the cases I run into the problem that I'm not at the…
Wannes
  • 1
0
votes
1 answer

NHibernate - Map key returned as proxy, eager load?

I'm mapping by code using NHibernate. Here is the class: [Serializable] public class Person : ObjectBase { public virtual IDictionary Attributes { get; set; } } and here is the mapping: public class PersonMapping :…
0
votes
1 answer

Flexibility with eager loading huge object graphs, NHibernate HQL TOP N in SQL

I need to pass POCO Domain objects (eagerly loaded). Having analyzed both Entity Framework and NHibernate, I can't find a solution! Analyzing the underlying SQL and queries by NHibernate, I discovered that ISession.CreateQuery (string…
0
votes
1 answer

Laravel eager loading result

I'm having trouble with eager loading in laravel I have these models: class Page extends Eloquent { public function translations() { return $this->has_many('Pagestl', 'page_id'); } } and class Pagestl extends Eloquent { …
Meddie
  • 571
  • 1
  • 7
  • 22
0
votes
1 answer

Dynamic lazyLoading - Entity Framework

I have a sqlSever database, reverse engineered with EF 5 By default, lazy Loading is disabled, I need to tell the context dynamically if related entities should be included or not (lazy loading) by passing a parameter to my method : public static…
SirZoro
  • 151
  • 1
  • 2
  • 10
0
votes
2 answers

Entity Framework POCO Eager Loading children

This is my POCO entities scenario: Manufacturer (1) has Cars (*) One Car entity has a navigation property to a Manufacturer entity. One Manufacturer entity has a navigation property to a Cars collection I need to query all Cars of a specified color,…
hamiltonjose
  • 461
  • 5
  • 14
0
votes
1 answer

Eager load grandchild attribute without child in rails

In Rails, I'm trying to eager load something to speed it up. I've got a Parent-Child-Grandchild situation, but only need the Parent and an attribute of the Grandchild. If I... Parent.all.includes(:child => :grandchild) then Bullet gripes about an…
robertmiles3
  • 899
  • 10
  • 20
0
votes
1 answer

Laravel Eager Loading

OK, here's my code: my relationships from my model // message model public function profile() { return $this->has_one('Profile', 'id'); } // profile model public function message(){ return $this->has_many('message',…
user1543871
  • 355
  • 1
  • 6
  • 16
0
votes
2 answers

Laravel 4 eloquent - Getting the id of self based on constraints of parents

I need to get the id of a row based on the constraints of the parents. I would like to do this using eloquent and keep it elegant. Some things to note when this process starts: I have - country_code(2 digit iso), lang_code(2 digit abbreviation for…
sir h4x0r
  • 1
  • 1
0
votes
1 answer

ActiveRecord - How to join association with pure SQL query

I'm doing the following query: TaskCheck.find_by_sql ["SELECT task_checks.*, tasks.* FROM task_checks INNER JOIN tasks ON task_checks.task_id = tasks.id"] It returns TaskCheck objects but when I try to read a Task field(joined in the query) then …
Jirico
  • 1,242
  • 1
  • 15
  • 29
0
votes
2 answers

Mass/Bulk SQL server updates

Code foreach (var item in _context.Duiven. .Include(p => p.Duivenmelker.VoedselInstelling) .Include(p => p.VoedselHistoriek) .Include(p => p.Duivenmelker.Personeel) …