Hi,
Just started learning active record and am wondering how to best retrieve data from multiple tables where an SQL aggregate query is involved.
In the following example (from a medical app) I'm looking for the most recent events of various types for each patient (e.g. last visit, last labtest etc). As you can see from the sql query be...
As my Rails app matures, it's becoming increasingly apparent that it has a strong data warehouse flavour, lacking only a facts table to make everything explicit.
On top of that, I just read Chapters 2 (Designing Beautiful APIs) and 3 (Mastering the Dynamic Toolkit) of Ruby Best Practices.
Now I'm trying to figure out how best to design...
I'm very new to CodeIgniter and Active Record in particular, I know how to do this well in normal SQL but I'm trying to learn.
How can I select some data from one of my tables, and then count how many rows are returned using CodeIgniters Active Record class?
Thanks,
Tom.
...
I need to cache (and expire) all the models in a table.
For example, if i have a model named Currency, i only have less than 10 possible currencies. Therefore, it would be nice to have:
class Currency < ActiveRecord::Base
cache_all(:expire_in => 10.minutes)
end
so that
Currency.all
Currency.find_by_name("USD")
should not hit the...
I have a class similar to the following:
class FruitKinds < ActiveRecord::Base
Apple = FruitKinds.find(:all).find { |fk|
fk.fruit_name == :apple.to_s
}
# ... other fruits
# no methods
end
Apple and other specific Fruits are commonly used as default values elsewhere in my application, so I want a handy means to refer to t...
I need 2 db connections in my rails model, is there a not so hackey way to do that?
any links or search keywords would be great :)
...
Have Addresses and Lists with many-to-many relationship, as shown below.
Sometimes need all the Lists an Address is not in.
Using the find_by_sql query shown, and it works great. But is there a way to do it without using direct SQL?
class List
has_many :address_list_memberships
has_many :addresses, :through => :address_list_member...
I have 3 classes related by habtm associations...Users, Locations, Employees.
Users is related to Locations via a habtm relationship, and Locations is related to Employees via a habtm relationship.
What I would like to be able to do is say:
current_user.locations.employees
Does anyone know the "Rails Way" to do this? I can do it in ...
I've currently got a site that depends on an Active Record pattern using the Doctrine ORM in PHP. I'm generally a fan of this approach - it's very straightforward and works well for managing for simple CRUD apps. But as this site grows, I think my need for more robust domain functionality will grow as well. I was wondering what other kin...
I have an active record class
class Service_Catalogue < ActiveRecord::Base
set_table_name "service_catalogue"
set_primary_key "myKey"
end
myKey is an nvarchar (sql server).
When I try and save it
service_catalogue= Service_Catalogue.new()
service_catalogue.myKey = "somevalue"
service_catalogue.save
I get the fol...
Hi
I need a list with all models (class_names) which have the pattern "Cube" at the end.
example:
all my models:
ModelFoo, ModelBar, ModelBarCube, Mode2BarCube
what I need:
['ModelBarCube', 'Mode2BarCube']
...
I have a has_many_polymorphs relationship between a Candidate and many events of various type. In particular, a Candidate creates a Created event when it is created.
class Candidate < ActiveRecord::Base
has_many_polymorphs :events, :through => :candidate_events,
:from => Event::Base.included_in_classes.m...
I'm considering using Sequel for some of my hairier SQL that I find too hard to craft in Active Record.
Are there any things I need to be aware of when using Sequel and ActiveRecord on the same project? (Besides the obvious ones like no AR validations in sequel etc...)
...
Do Ruby on Rails' ActiveRecord dynamic finders have a problem in that they don't explicitly tell clients about their interface?
Clients = client code or developers creating the client code. What uses the ActiveRecord. If you use the active record, is it clear from looking at the class what you can do with it, what it needs or how you ca...
There seems to be no name for this common model pattern.
It's used in many plugins like acts_as_taggable[_whatever] and it basically allows
linking a certain model, like Tag, with any other model without having to put
ever-more belongs_to statements in the Tag model.
It works by having your model (Tag) linked to a polymorphic join mo...
i have budgets table with emptype_id and calendar_id actual_head, estimated_head
when i do Budgets.sum(:actual_head ,:group=>"emptype_id,calendar_id") i do not get the result grouped by the above two columns but only by the emptype_id
however when i check the log the sql query is right
"SELECT sum(budgets.actual_head) AS sum_ac...
Best way to load seed data? I have an Author table that is tightly coupled with a Users table. I also have migrations to alter both of these tables. I want to add a default admin user but I want to make sure that both tables are created and all migrations have run for these tables before my CreateDefaultAdmin (or whatever) migration runs...
I have four tables: jp_properties, cn_properties, jp_dictionaries and cn_dictioanries.
And every jp_property belongs to a jp_dictionary with foreign key "dictionary_id" in table.
Similarly, every cn_property belongs to a cn_dictionary with foreign key "dictionary_id" in table too.
Since there are a lot of same functions in both proper...
I have a rails app I created with based on a DB with a table named "countries", which stored a list of all the countries in the world. Now I have found out that the actual DB I will be using uses a table named "ctry" instead (stupid I know). What I am trying to figure out is if there is any way I can point active record to this new table...
Can anyone tell me what is the difference between build and new command on Rails?
...