eager-loading

With function not working to load has many relation data laravel Model Eloquent

笑着哭i 提交于 2019-12-24 07:58:31
问题 I have these two model. This phone model is a common model which can be used to save and fetch the phone value for a user, customer, Employee and so on. So the meta_value is used to save the id of related model and meta_key is used to determine the model name relation. /* Customer Model*/ namespace App; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; class Customer extends Model { /** * Get the Phone List. */ public function phones(){ return $this-

Laravel Eager Load with dynamic constraints

不想你离开。 提交于 2019-12-24 06:39:26
问题 Can anybody please help me to understand why the following code is working $x = $widget->objGallery->galleryItems()->with(array('captions' => function($query){ $query->where('locale', 'IT' );}))->get() ; but when I am using a dynamic value $id='11'; $x = $widget->objGallery->galleryItems()->with(array('captions' => function($query){ $query->where('locale', $id );}))->get() ; is saying Method Illuminate\View\View::__toString() must not throw an exception 回答1: In fact it's hard to say because

Entity Framework code first - Many to Many - Include conditional

杀马特。学长 韩版系。学妹 提交于 2019-12-24 04:08:05
问题 I have two Entities Store and Catalog , having many to many relationship using fluent Api. I want to get a Store by id with all the catalogs having status equals to "Published". Below I try to write the following query but not getting the expected results. var store = context.Stores.Include("Catalogs").Where(s => s.StoreID == id && s.Catalogs.Any(c => c.Status == "Published")).SingleOrDefault(); 回答1: What you're asking for there is "give me the store with this ID, but only if it has a

Hibernate One To Many Eager Not Pulling in all Data

孤人 提交于 2019-12-23 04:45:29
问题 I am doing an eager load on a one to many relationship in hibernate. The parent items are pulled back correctly but they only recieve one item each in their child list. One of the parent's should have two. I run the query Eclipse spits out, and it pulls the correct results. Question is why would only one item go into each list when one should have two? @OneToMany(mappedBy="badge", fetch=FetchType.EAGER) public List<BadgeLevel> getBadgeLevels() { return this.badgelevels; } SQL select * from (

Why doesnt NHibernate eager fetch my data

被刻印的时光 ゝ 提交于 2019-12-22 12:12:27
问题 I am using Nhibernate for my ORM. I have a class "Control" that has a one to many relationship with ControlDetail (ie. A control has many controlDetails). In the control xml config it has the following <bag name="ControlDetails" lazy="true" access="property" order-by="SortOrder asc" cascade="all-delete-orphan" table="ControlDetail"> <key column="ControlID"/> <one-to-many class="ControlDetail"/> </bag> such that I believe unless otherwise told it would lazy load the controldetails of a control

Rails 4 Eager load limit subquery

一笑奈何 提交于 2019-12-22 11:25:52
问题 Is there a way to avoid the n+1 problem when eager loading and also applying a limit to the subquery? I want to avoid lots of sql queries like this: Category.all.each do |category| category.posts.limit(10) end But I also want to only get 10 posts per category, so the standard eager loading, which gets all the posts, does not suffice: Category.includes(:posts).all What is the best way to solve this problem? Is N+1 the only way to limit the amount of posts per category? 回答1: From the Rails docs

belongs_to association loaded individually even after eager loading

假如想象 提交于 2019-12-22 10:57:06
问题 I have the below association class Picture < ActiveRecord::Base belongs_to :user end class User < ActiveRecord::Base has_many :pictures end And in my PicturesController i am eager loading the user class PicturesController < ApplicationController def index @pictures = Picture.includes(:user).all end end In my view, i am displaying each pictures user name -@pictures.each do |picture| %tr %td= picture.name %td= picture.user.name Now the question is, even though i am eager loading the user, i see

Am I doing something wrong with Nhibernate Query Over fetch?

限于喜欢 提交于 2019-12-22 10:23:44
问题 I have this using (ITransaction transaction = session.BeginTransaction()) { Task tAlias = null; CompletedTask cAlias = null; List<Task> tasks = session.QueryOver<Task>(() => tAlias) .Where(Restrictions.In(Projections.Property(() => tAlias.Course.Id), courseIds)) .Fetch(pt => pt.PersonalTaskReminders).Eager .List<Task>().ToList().ConvertToLocalTime(student); transaction.Commit(); return tasks; } PersonalTaskReminders == Collection So a task can have many personalTaskReminders. I am finding

Good behaviour for eager loading multiple siblings and grandchildren (cousins?) in NHibernate 3.0 Linq

前提是你 提交于 2019-12-22 09:05:36
问题 I'm trying to do the following with NHibernate 3.0's LINQ interface. I want to query for an object (using some Where clause), and load some children and grandchildren. Currently I'm doing it like so: var results = session.Query<Thing>() .Where(...) .Fetch(x => x.SubThingA) .ThenFetch(st => st.SubSubThingA) .Fetch(x => x.SubThingB) .ThenFetch(st => st.SubSubThingB) // etc... However, this results in a Cartesian product between all grandchildren (every result row contains many, many columns).

Entity Framework 4 Abstract Model - How to Programatically Eager-Load Navigational Properties?

∥☆過路亽.° 提交于 2019-12-22 08:24:17
问题 I have an EF4 Model that is built with abstract entities/classes: Notice how State entity has a navigational property called Country . Note: I have lazy-loading disabled, so i must eager-load on demand. Now, if i have the following method: public Location FindSingle(int id) { return _repository.Find().WithId(id).SingleOrDefault(); } This does not return any associations by default. But how can i dynamically eager-load the associations when i explicitly want to? I cannot do this: return