I'm trying to avoid the N+1 queries problem with eager loading, but it's not working. The associated models are still being loaded individually.
Here are the relevant ActiveRecords and their relationships:
class Player < ActiveRecord::Base
has_one :tableau
end
Class Tableau < ActiveRecord::Base
belongs_to :player
has_many :table...
I have the following (simplified) class hierarchy:
def Parent < ActiveRecord::Base end
def Child < Parent
belongs_to :other
end
def Other < ActiveRecord::Base end
I want to get all Parent objects and -if they are Child objects- have them eager load the :other association. So I had hoped I could do:
Parent.find(:all, :include => [:o...
Hello, I have a Topic and a Project model. I have a Many-to-many ass between them (HABTM one).
In the Topic's Index Page, I want to display the number of projects that each topic have. So I have
@topics = Topic.all(:include => [:projects])
In my controller, and so far so good. The problem is that the Project Model is so big that the ...
I have a problem trying to load a tree, this is my case, I have an entity associated with itself (Hierarchic) with n levels; the question is, Can I load eagerly the entire tree using ICriteria or HQL?
Thanks in advance for any help.
Ariel
...
I have a databound grid at my view (XAML) and the Itemsource points to a ReportsCollection. The Reports entity has three primitives and some complex types. These three are shown as expected at datagrid. Additionally the Reports entity has a property of type Store. When loading Reports via GetReports domain method, I quickly figure out th...
Hi folks,
i'm trying to eager load some child entity, and when I try to add the Include() method, i'm getting a compiler error (ie. it can't find it).
er ... can anyone help me out on this one, please?
...
Ya is this possible :) ?
...
In EF eager loading related entities is easy.
But I'm having difficulties including inherited entities when loading data using table-per-type model.
This is my model:
Entities:
ArticleBase (base article entity)
ArticleSpecial (inherited from ArticleBase)
UserBase (base user entity)
UserSpecial (inherited from UserBase)
Image
R...
I have a Parent class with a List of children. I would like to load the Parent by something other than the id e.g. by name...I am using criteria.setFetchMode("children",FetchMode.JOIN);
and criteria.add(Restrictions.eq("name", name)) to eagerly load all the data for the parent with a unique name. Problem is I get back thousands of result...
Imagine a simple case like this:
class Book
has_many :chapters
end
Let's say in my controller I do something like this:
book = Book.find(:first,
:include => :chapters,
:conditions => ['chapters.title = ?', "In the beginning"]
Now let's say I want to display the chapter. How can I address the c...
When working with a polymorphic association, is it possible to run an include on submodels that are only present in some types?
Example:
class Container
belongs_to :contents, :polymorphic => true
end
class Food
has_one :container
belongs_to :expiration
end
class Things
has_one :container
end
In the view I'm going to want to d...
Hi,
i have 2 models - Issue and Answers (issue has many answers) and both have translations with globalize2. Every time i attempting to load Issue with answers via
@issue = Issue.find(params[:id])
@answers = @issue.answers
causes loading of translations for each Answer (1 sql query per Answer).
How can i optimize it?
...
The goal is to issue the fewest queries to SQL Server using LINQ to SQL without using anonymous types. The return type for the method will need to be IList<Child1>. The relationships are as follows:
Parent
Child1 Child2
Grandchild1
Parent > Child1 is a one-to-many relationship
Child1 > Grandchild1 is a one-to...
Simple task: given that an article has many comments, be able to display in a long list of articles how many comments each article has. I'm trying to work out how to preload this data with Arel.
The "Complex Aggregations" section of the README file seems to discuss that type of situation, but it doesn't exactly offer sample code, nor do...
Hi all. This questions doesn't let me sleep as it's since one year I'm trying to find a solution but... still nothing happened in my mind. Probably you can help me, because I think this is a very common issue.
I've a n-layered application: presentation layer, business logic layer, model layer. Suppose for simplicity that my application ...
Is it possible to eagerly load polymorphic association using Linq and NH?
For example: Company is base class, Department is inherited from Company, and Company has association Employees to the User (one-to-many) and also association to the Country (many-to-one).
Here is mapping part related to inherited class (without User and Country c...
I have a query which is something like this:
Session.CreateSQLQuery(
@"SELECT f.*, b.*, z.* FROM Foo f
LEFT OUTER JOIN Bar b ON b.Id = f.BarId
LEFT OUTER JOIN Zar z ON z.Id = b.ZarId"
)
.AddEntity("f", typeof(Foo))
.AddJoin("b", "f.BarId")
.AddJoin("z", "b.ZarId")
.List<Foo>();
The problem is that I ...
Hi, I have rails app which has a list of users. I have different relations between users, for example worked with, friend, preferred. When listing the users i have to decide if the current user can add a specific user to his friends.
-if current_user.can_request_friendship_with(user)
=add_to_friends(user)
-else
=re...
I have a page that's taking ages to render out. Half of the time (3 seconds) is spent on a .find call which has a bunch of eager-loaded associations. All i actually need is the number of associated records in each case, to display in a table: i don't need the actual records themselves. Is there a way to just eager load the count? Her...
I have a need to load an entire LINQ-to-SQL object graph from a certain point downwards, loading all child collections and the objects within them etc. This is going to be used to dump out the object structure and data to XML.
Is there a way to do this without generating a large hard coded set of DataLoadOptions to 'shape' my data?
...