Is it possible to use an attribute of a child to group a query?
Post.find(:all, :include => [ :authors, :comments ], :group=>'authors.city') does not work.
However, I am able to use author.city as part of the conditions.
...
Background
Normal rails eager-loading of collections works like this:
Person.find(:all, :include=>:companies)
This generates some sql which does
LEFT OUTER JOIN companies ON people.company_id = companies.id
Question
However, I need a custom join (this could also arise if I was using find_by_sql) so I can't use the vanilla :includ...
I'd like the canonical way to do this. My Google searches have come up short. I have one ActiveRecord model that should map to a different database than the rest of the application. I would like to store the new configurations in the database.yml file as well.
I understand that establish_connection should be called, but it's not clea...
I'm creating an ORM in PHP, and I've got a class 'ORM' which basically creates an object corresponding to a database table (I'm aiming for similar to/same functionality as an ActiveRecord pattern.) ORM itself extends 'Database', which sets up the database connection.
So, I can call: $c = new Customer();
$c->name = 'John Smith';
$c->sav...
I have this problem, I'm using Castle ActiveRecord and when I update I verify changes in the object in the OnFlushDirty event.
However, when I access to the previouState["MyProperty"], it turns to be null and I can't get the old value.
Do you know why?
this is the code;
protected override bool OnFlushDirty(object id, System.Colle...
Hi all,
I'm getting some objects from an external library and I need to store those objects in a database. Is there a way to create the tables and relationships starting from the objects, or I have to dig into them and create migrations and models by hand?
Thanks!
Roberto
...
How do I get a list of all the tables defined for the database when using active record?
...
I'm working on a project for my school on rails (don't worry this is not graded on code) and I'm looking for a clean way to traverse relationships in ActiveRecord.
I have ActiveRecord classes called Users, Groups and Assignments. Users and Groups have a HABTM relationship as well as Groups and Assignments. Now what I need is a User func...
I've been developing web applications for a while and i am quite comfortable with mySql, in fact as many do i use some form of SQL almost every day. I like the syntax and a have zero problems writing queries or optimizing my tables. I have enjoyed this mysql api.
The thing that has been bugging me is Ruby on Rails uses ActiveRecord an...
I use serialize in one ActiveRecord model to serialize an Array of simple Hashes into a text database field. I even use the second parameter to coerce deserialization into Arrays.
class Shop < ActiveRecord::Base
serialize : recipients, Array
end
It seems to work fine but, after a few requests, the content of recipients turns to Hash...
I get a mysql error:
#update (ActiveRecord::StatementInvalid) "Mysql::Error: #HY000Got error 139 from storage engine:
When trying to update a text field on a record with a string of length 1429 characters, any ideas on how to track down the problem?
Below is the stacktrace.
from /var/www/releases/20081002155111/vendor/rails/activere...
I'm trying to create a named_scope that uses a join, but although the generated SQL looks right, the result are garbage. For example:
class Clip < ActiveRecord::Base
named_scope :visible, {
:joins => "INNER JOIN series ON series.id = clips.owner_id INNER JOIN shows on shows.id = series.show_id",
:conditions=>"shows.visi...
I have an application in which attr_accessor is being used to keep temporary data for a model which will be passed to a rake task. Seeing there is not a database field for these attributes and they are not being calculated from database data, will the attr_accessor data persist and be available to the rake task? What happens if I need ...
I am in the start up of a project using ASP.NET MVC and have started creating my models. Since I know some Ruby On Rails and would like to use a system as similar to Rails Active Record as possible.
Have anyone used Castle Projects Active Record in a ASP.NET MVC application (or any application that is relevant) and have some experience ...
In our program, each customer gets their own database. We e-mail them a link that connects them to their database. The link contains a GUID that lets the program know which database to connect to.
How do I dynamically and programatically connect ActiveRecord to the right db?
...
have you re-factored from an Active Record to a Data Mapper pattern? what conditions prompted the switch? i'm primarily interested in web based applications, but would like to know the challenges that accompany such a move in any environment.
...
Let's say I'm writing a Library application for a publishing company who already has a People application.
So in my Library application I have
class Person < ActiveResource::Base
self.site = "http://api.people.mypublisher.com/"
end
and now I want to store Articles for each Person:
class Article < ActiveRecord::Base
belongs_to :...
This is an age-old question where given a table with attributes 'type', 'variety' and 'price', that you fetch the record with the minimum price for each type there is.
In SQL, we can do this by:
select f.type, f.variety, f.price
from ( select type, min(price) as minprice from table group by type ) as x
inner join table as f on f....
I have named_scope which is reused in multiple ActiveRecord models.
For example:
named_scope :limit, lambda {|limit| {:limit => limit}}
What is the best practice to extract this code to be shared across models.
Is it possible to extract it to a module or should I rather reopen ActiveRecord::Base class?
...
I'm building an app in Ruby on Rails, and I'm including 3 of my models (and their migration scripts) to show what I'm trying to do, and what isn't working. Here's the rundown: I have users in my application that belong to teams, and each team can have multiple coaches. I want to be able to pull a list of the coaches that are applicable...