eager-loading

Doctrine 2 - Eager loading doesn't appear to work with ManyToMany

☆樱花仙子☆ 提交于 2019-12-08 00:45:03
问题 I have three entities: SequenceRun has one MaterialTypeString , and has many User . I.e. There is a OneToMany relationship between SequenceRun and MaterialTypeString , and a ManyToMany relationship between SequenceRun and User . SequenceRun.php: /** * @ORM\ManyToOne(targetEntity="MaterialTypeStrings", inversedBy="sequenceRuns") * @ORM\JoinColumn(name="material_type_strings_id", referencedColumnName="id") */ private $materialTypeString; /** * Many Groups have Many Users. * @ORM\ManyToMany

Sequelize Top level where with eagerly loaded models creates sub query

白昼怎懂夜的黑 提交于 2019-12-07 15:55:31
I'm running an into issue where Sequelize creates a subquery of the primary model and then joins the includes with that subquery instead of directly with the primary model table. The query conditions for the include(s) ends up inside the subquery's WHERE clause which makes it invalid. I have shortened names down trying to keep this compact hopefully without losing any relevant info. Environment: Nodejs: 6.11.3 Sequelize: 3.23.6 => Updated to 4.38.1 and problem persists MySql: 5.7.23 Code snip models: I.model: models.I.hasMany(models.II); models.I.belongsTo(models.CJ); models.I.belongsTo(models

Loading data from associated model in same query in rails

青春壹個敷衍的年華 提交于 2019-12-07 14:03:11
问题 Basically, I have a Listing model, where each listing has a country id. I need the country name in my search results view. I know I can do @listing.country.name , but this performs an extra query for each listing in my search results. I'm using Thinking Sphinx, and in my controller I have @listings = Listing.search(@ts_params).page(page_num).per(limit) I have tried adding .includes(:countries) and variations thereof but no luck. What's the best way to go about this? I want the country data to

Eager loading of deleted records with paranoia's default scope

我是研究僧i 提交于 2019-12-07 10:58:28
问题 I'm using the paranoia gem to "soft-delete" records. Now I need to eager load these records, some of which might have been deleted, for an associated model. Paranoia adds this default_scope to the "paranoid" model: default_scope :conditions => { :deleted_at => nil } So in effect, I have these (simplified) models: class Product has_many :orders default_scope :conditions => { :deleted_at => nil } end class Order belongs_to :product end What I'm trying to achieve is to eager-load the products

How do we load related objects (Eager Loading) in Dot Net based Azure Mobile Service?

跟風遠走 提交于 2019-12-07 10:28:26
问题 If I have following model structure public class QuestionItem: EntityData { public string Content { get; set; } public bool IsAnswered { get; set; } public int NumberOfAnswers { //todo: make it computable get; set; } public UserItem By { get; set; } public string ById { get; set; } public string AtLocation { get; set; } } & parent entity as public class UserItem:EntityData { public string UserName { get; set; } public string Gender { get; set; } public string BaseLocation { get; set; } public

laravel eager loading using with() vs load() after creating the parent model

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-07 06:44:46
问题 I am creating a Reply model and then trying to return the object with it's owner relation. Here is the code that returns an empty object: //file: Thread.php //this returns an empty object !!?? public function addReply($reply) { $new_reply = $this->replies()->create($reply); return $new_reply->with('owner'); } However, if i swap the with() method for load() method to load the owner relation, i get the expected result. That is the reply object is returned with it's associated owner relation: /

Entity Framework Eager Loading Filter

百般思念 提交于 2019-12-07 06:10:37
问题 I have a simple query I want to do like this: 1) Products have ChildProducts which have PriceTiers 2) I want to get all the Products that have a Category with a ID of 1 and Display = true. 3) I want to then include all the ChildProducts that have Display = true. 4) And then include the PriceTiers that have IsActive = true. From what I have read, EF does not support Eager Loading with filters, so the following will not work: ProductRepository.Query.IncludeCollection(Function(x) x.ChildProducts

NHibernate ThenFetchMany is retrieving duplicate children

余生长醉 提交于 2019-12-07 05:06:24
问题 I have a parent object with a child collection containing one element, the child collection contains a "grandchild" collection containing 3 elements. I am loading the parent object from the database using NHibernate as follows Parent parentObject = session.Query<Parent>() .FetchMany(x => x.Children) .ThenFetchMany(x => x.GrandChildren) .Where(x => x.Id = "someparentid") .Single(); What I'm finding is that there are duplicate children objects (3 in total) attached to the parent object when

How addSelect() Builder method works in Laravel

拥有回忆 提交于 2019-12-07 03:46:25
问题 Say I have these models: User Model namespace App; use Illuminate\Database\Eloquent\Model; class User extends Model { /** * The table associated with the model. * * @var string */ protected $table = 'User'; protected $fillable = [ 'username', 'favoriteColor' ]; public function flights() { return $this->hasMany('App\Flight'); } } Flight Model namespace App; use Illuminate\Database\Eloquent\Model; class Flight extends Model { /** * The table associated with the model. * * @var string */

LINQ to SQL eager loading with conditions

喜夏-厌秋 提交于 2019-12-07 01:55:37
问题 I'm trying to learn LINQ to SQL and i've found out about the LoadWith function. All the examples i've found will load all records from the table you specify in the LoadWith function e.g. var dlo = new DataLoadOptions(); dlo.LoadWith<Blog>(b => b.Posts); this.LoadOptions = dlo; What I would like to know is if it's possible to load in this example only the last blog post? I've tried dlo.LoadWith<Blog>(b => b.Posts.Max()); But it doesn't like that syntax. 回答1: You can do it using AssociateWith.