eager-loading

Rails 3 refuses to eager load

試著忘記壹切 提交于 2019-12-11 17:33:18
问题 I'm working in Rails 3.0.7. I have some many-to-many and some one-to-many associations that fail to eager load. My associations are: Person has_many :friends Person has_many :locations through=> :location_histories Location belongs_to :location_hour Location_hour has_many :locations In my controller I have the following: @people = Person.includes([[:locations=>:location_hour],:friends]).where("(location_histories.current = true) AND (people.name LIKE ? OR friends.first_name LIKE ? OR friends

How to eager load the 'user' function from eloquent relationship previously set (User Model) in controller when I have this situation

南笙酒味 提交于 2019-12-11 16:39:41
问题 NOTE: The relationship between Post and Tag model is many to many and the relationship between User and Post model is one to Many. Everything is working well I just have too many Queries from users where users.id... when debbug it. I want to use eager loading for the user function, in this situation in my controller function. How do I use it like with('user')->get(); Thanks. This is my web.php route: Route::get('/posts/tags/tag/{tag}', 'TagsController@show'); This is my controller function

Yii eager loading — Fatal error: Out of memory

↘锁芯ラ 提交于 2019-12-11 14:08:08
问题 I have a problem with Yii eager loading. I open user profile page and use: $model=User::model()->with('routes', 'likes', 'comments', 'questions', 'cityname')->findByPk($id); Relations is: public function relations() { return array( 'routes'=>array(self::HAS_MANY, 'Route', 'author_id', 'order'=>'routes.id DESC'), 'questions'=>array(self::HAS_MANY, 'Question', 'author_id', 'order'=>'questions.id DESC'), 'comments'=>array(self::HAS_MANY, 'Comment', 'author_id', 'order'=>'comments.id DESC',),

Can't get where query to do eager loading of one-to-many association

血红的双手。 提交于 2019-12-11 12:59:34
问题 I am using Grails v3.3.9. I cannot get queries to eagerly load one-to-many association. Tried all sorts of ways. This is posted relative to trying to use this in unit testing (fails on app at runtime as well). Scenario: I have two domain classes, one called 'OrgRoleInstance' which has Collection<Site> sites, and static hasMany =[sites:Site] , and the other called 'Site' which has a static belongsTo = [org:OrgRoleInstance] . This is birdirectional one-to-many from orgs to sites. I create a new

Hibernate : Force lazy-loadding on eager field

杀马特。学长 韩版系。学妹 提交于 2019-12-11 11:56:32
问题 One of our model object in our application has many fields configured to be eagerly fetched like so: @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "field") public Field getField() { return this.field; } However I sometime do not need these information, which slow down my queries for nothing. I cannot change the behaviour and use FetchType.LAZY instead as I've no idea what will be the impact on the whole application (legacy...). Is there a way to simply tell hibernate to fetch nothing

Join several queries to optimise QueryOver query

冷暖自知 提交于 2019-12-11 06:58:29
问题 I am using NHibernate and while traversing my code I came upon two functions that are called in sequence. They are probably a school example of 1) extra database round trip and 2) in-memory processing at the application side. The code involved is: // 1) Getting the surveys in advance var surveys = DatabaseServices.Session.QueryOver<Survey>() .Where(x => x.AboutCompany.IsIn(companyAccounts.ToList())) // Actual query that can be optimized var unverifiedSurveys = DatabaseServices.Session

select coordinates at other tables

 ̄綄美尐妖づ 提交于 2019-12-11 06:56:37
问题 I want to get all nearest items, the coordinates are saved at listings table. items and listings are many to many relationship. Then it will be sorted either by distance or low to high price. $items = Item::with('listings') ->select('*'); if($request->sortby == 'distance'){ $items->distance($lat,$lng); } if($request->sortby == 'low'){ $items->groupBy('listings.id') ->orderBy('items.price'); } $items = $items->paginate(10); This is my Item model for distance public function scopeDistance(

Laravel 4: fetching only models that have related models

半城伤御伤魂 提交于 2019-12-11 06:26:15
问题 I want to only retrieve a model(s) when they have a specific related model present e.g. $posts = Post::has('comment')->get(); that works fine although the opposite does not: $comments = Comment::has('post')->get(); I get the following error: Has method invalid on "belongsTo" relations. Basically the reason i want to do this is that in exceptional circumstances there are cases that when i call a related model in a view, that model may not have a related model present (even when it should)

Trouble on eager loading and using the 'where' method

旧街凉风 提交于 2019-12-11 04:54:14
问题 I am running Ruby on Rails 3.1. I am using the includes method and I would like to understand why when I call the where method on an eager loaded collection it reloads associated objects instead of just finding that object in the eager loaded collection. Since all related objects are already been eager loaded I expect that the where method does not hit the database to reload those objects! That is, I have the following: article_categories = article .categories .where(:user_id => @current_user

Loading Complete graph from Sql using LINQ

北战南征 提交于 2019-12-11 04:53:13
问题 Assume we have a Menu class that has SubMenus (which is the same type of Menu therefore can have SubMenus and Items too) and Items (which has a different type) and we stored them in two tables(One for Menus and one for Items). Is there any way to load complete graph of the Menu class (all of its SubMenus and Items) using LINQ to SQL? 回答1: If you define the relationships properly in SQL, LINQToSQL should give you back all of the menus/items with a single query on menus. However, this won't