eager-loading

Completing object with its relations and avoiding unnecessary queries in sqlalchemy

旧城冷巷雨未停 提交于 2020-01-01 10:07:08
问题 I have some database structure; as most of it is irrelevant for us, i'll describe just some relevant pieces. Let's lake Item object as example: items_table = Table("invtypes", gdata_meta, Column("typeID", Integer, primary_key = True), Column("typeName", String, index=True), Column("marketGroupID", Integer, ForeignKey("invmarketgroups.marketGroupID")), Column("groupID", Integer, ForeignKey("invgroups.groupID"), index=True)) mapper(Item, items_table, properties = {"group" : relation(Group,

LINQ to Entity Framework Many-Many Eager Loading issue

徘徊边缘 提交于 2020-01-01 07:26:07
问题 I have the following query: var MyQuery = from e in ContractContext.Equipments.Include("Manufacturers") where e.Customers.ID == customer.ID select e; And everything works, I get my Equipments and it loads the Manufacturers table correctly (eagerly). But when I try to do the following many-to-many query: var MyQuery = from e in ContractContext.Equipments.Include("Manufacturers") where e.Customers.ID == customer.ID from cce in e.ContractEquipments where cce.Contracts.EndedOn >= DateTime.Today

Laravel dynamic relationships - access model attributes on eager load

喜欢而已 提交于 2020-01-01 07:04:40
问题 I have an Eloquent relationship on my Laravel model which is dynamic - that is, the value of a particular database field determines which model will get loaded. I am able to load this relationship fine when I first instantiate the model instance and then reference the relation, but it does not work when I eager load that relationship. Specifically, I have a Product model. That product might or might not be a parent to another product. If the parent_id of the Product is set to 0 then that

Disable eager relations

痞子三分冷 提交于 2020-01-01 04:07:08
问题 In my project I have many Eloquent models that have eager relations configured in class like this: protected $with = [ 'countries', 'roles' ]; But sometimes I need just old plain model without any relations. Can I somehow do: Model::noRelations()->all() Really don't wanna use query builder nor create another class just for few occasions. 回答1: If you have to set the $with property on your model rather than leaving it empty, you can manually override the relationships that need to be eager

Eager fetch performs left join in hibernate but fires seperate sql queries in springboot/JPA

天大地大妈咪最大 提交于 2019-12-31 05:19:05
问题 I see a lot of posts where Eager fetch performs left join of child table parent table in hibernate. But when I use springboot , hibernate fires seperate sql queries - means one select query for parent table and one select query for child table. Why is there a difference? Has there been any upgrades in springboot or is it something I am doing wrong ? Below are the entities I am using: Order Entity: @Entity @Table(name="Ordertable", schema="cf_2583f365_c3c6_499a_a60d_138e7e7023eb") public class

Eager loading with Linq query with restriction on details

 ̄綄美尐妖づ 提交于 2019-12-25 08:41:26
问题 How can I write a query with the build-in linq provider of NHibernate including eager loading and restrictions on the details? For example public class Library { public Library() { Books = new List<Book>(); } public virtual int Id { get; set; } public virtual string Name { get; set; } public virtual IList<Book> Books { get; protected internal set; } } public class Book { public Book() { Pages = new List<Page>(); } public virtual int Id { get; set; } public virtual Library Library { get; set;

Entity Framework 5 - Is it possible to load relationships (associations) without lazy and eager loading?

狂风中的少年 提交于 2019-12-25 04:58:09
问题 I'm trying to develop a generic repository on Entity Framework 5 for get data from any table and I want to use disconnected context without lazy and eager loading. Is it possible? I'm using the code below, but it doesn't works: T it's entity type. public IList<T> GetData(Expression<Func<T, bool>> expression) { using (var context = new Context()) { return context.Set<T>().Where(expression).ToList(); } } Just the main entity it's loaded, the relationships no. 来源: https://stackoverflow.com

How do I eager load two levels of associations in 1 call?

强颜欢笑 提交于 2019-12-25 01:44:10
问题 I have FamilyTree, Node, Comment, & User models. The relationship is like this: FamilyTree class FamilyTree < ActiveRecord::Base belongs_to :user has_many :memberships, dependent: :destroy has_many :members, through: :memberships, source: :user, dependent: :destroy has_many :nodes, dependent: :destroy end Node class Node < ActiveRecord::Base belongs_to :family_tree belongs_to :user has_many :comments, dependent: :destroy end Comment class Comment < ActiveRecord::Base belongs_to :user belongs

How can I map data from associations in “Edit” Forms in Rails?

烂漫一生 提交于 2019-12-25 01:12:01
问题 This is a follow-up to How to I serve data from an object's associations in rails forms? I am wondering, I would like to use eager loading to serve to an edit page of an Article object the tags (as well as other attributes that are saved through associated tables. In the previous question, I was informed that I could use eager loading of associations to pre-load that data. IE in the controller I augment the .find call to include @article = Article.find(params[:id], :include => [:tags]) This

Eager-Loading based on the first query

与世无争的帅哥 提交于 2019-12-24 10:24:47
问题 Query where the problem lies \DB::enableQueryLog(); $place = Place::near($user)->with(['services','services.registrable' => function (MorphTo $query) { $query->where('distance_of_visibility', '<', \DB::raw('places.distance')); }])->find(22); \DB::disableQueryLog(); dd(\DB::getQueryLog()); Generated queries First: The queries will calculate all the places in a given radius and add the calculated field distance to the select select *, st_distance_sphere(`location`, ST_GeomFromText(0.000000 00