I am having a problem with ActiveRecord inserting the DATETIME as per the documentation; "Active Record automatically timestamps create and update operations if the table has fields named created_at/created_on or updated_at/updated_on." I have a column named created_at but ActiveRecord is not inserting the DATETIME. My insert query looks...
I'm terrible at naming and realize that there are a better set of names for my models in my Rails app. Is there a way to use a migration to rename a model and its table?
...
I have an app where I want to link an instance of a model to another instance of the same model via another model (i.e. Task1 > Relationship < Task2) and am wondering if I can use has_many :through for this.
Basically, the relationship model would have extra information (type_of_relationship, lag) so it would be ideal to have it as a jo...
Is there a way that I can get a list of the models that a particular model belongs to in Rails?
For example:
class Project < ActiveRecord::Base
has_one :status
...
end
class Task < ActiveRecord::Base
has_one :status
...
end
class Status < ActiveRecord::Base
belongs_to :project
belongs_to :task
# this is where I want to...
Right now I am trying to call my model, and spit out its results into json/xml format. My only problem is, my database associations aren't being loaded or queried.
Normally, I can just run this
@campaign = Campaign.find(:all)
Then get the number of hits by calling, @campaign[0].hits through the has_many :hits.
But if you debug the ou...
Hi,
I have the following Rails definition:
Class Book
string title
has_many readings
has_many users, :through => :readings
Class Reader
int rating
belongs_to :book
belongs_to :user
Class User
has_many readings
has_many books, through => :readings
No I want to query like this:
Give me all readings ratings for user A that have book.t...
Is there any attribute that one can put on a parameter for an action that tells LINQ to load a particular entity and only databind on the values that have changed a la Active Record/Monorail (see ARDataBinding)
...
What is the best/cleanest/easiest way to maintain the edit history of records in Rails?
I'm looking for logging - who made the edits and when and the ability to rollback to earlier versions of records.
My guess is that you would use ActiveRecord callbacks on updates or deletes and instead of updating/deleting records you would create a...
I'm writing a model that handles user input from a text area. Following the advice from http://blog.caboo.se/articles/2008/8/25/sanitize-your-users-html-input, I'm cleaning up the input in the model before saving to database, using the before_validate callback.
The relevant parts of my model look like this:
include ActionView::Helpers...
I'm really struggling to wrap my head around some of this stuff. Let me give an example of where I'm struggling.
I'm using Linq-2-Sql as the DAL for my app and the IRepository pattern used in the MVC Storefront sample app from Rob Conery.
In my domain I have a Customer Model which has a collection of Address Models. In my UI there is a...
Hi, I'd like to get the objects that are updated in the last 10 seconds from the ActiveRecord's find.
I tried doing this
@chats = Chat.find(:all, :conditions => ["updated_at > ?", 10.seconds.ago] )
as well as
@chats = Chat.find(:all, :conditions => ["updated_at > ?", Time.now-10.seconds] )
and even
@chats = Chat.find(:all, :con...
User model has three keys: is_master, is_standard, is_guest because I originally wanted to use activerecord boolean methods like is_master? or is_power?.
However, if it would be better to create a UserType relationship and create my own methods like this:
def master?
return true if self.user_type = 1
end
What's the best practice o...
I'm working on a Rails app that will serve as an authentication system for other Rails apps through Rails's ActiveResource functionality.
The authentication app has an ActiveRecord model called User. The client app has an ActiveResource model called User. I know that in the client app I can do stuff like user.save and it will perform a ...
An article has many articles that it refers to and many other articles can refer to it. Sometimes an article can refer to an article that also refers to it.
...
In a rails app, I using the :finder_sql option in a has_many declaration. The rails docs say that when I do this, "find_in_collection is not added." What does this mean?
...
I've got a legacy database with a bunch of idiotically named columns like:
some_field_c
some_other_field_c
a_third_field_c
I would very much like to make a Rails ActiveRecord sub-class that automatically aliases these attributes to their name minus the underscore and "c". However, when I tried:
attributes.each_key do | key |
name =...
Right now I have a table called Campaigns that has many Hits, if I call say:
Campaign.find(30).hits
Which takes 4 seconds, or 4213 ms.
If I call this instead:
campaign = Campaign.find(30)
campaign.hits.count
Does it still load all of the hits, then count? Or does it see I am counting and avoids loading all of the hits? (Which is cur...
Does LINQ to SQL provide out-of-the-box polymorphic associations as ruby on rails active record does? If not, is there any workaround to manually map those associations?
...
I need a .Net ORM, and I heard some good things about this. I've had NHibernate running in the past, but this seems to make a lot of things easier.
However, two things made me a little nervous.
It uses NHibernate 1.2, which seems old
It's still an RC with its last release 18 months ago
Is anyone using it, and do they recommend it f...
Given the following tables in ActiveRecord:
authors
sites
articles
I don't know how to express that an author is paid a different amount depending on the publication, but that authors working for the same publication have different rates:
John publishes an article in Foo for $300
John publishes an article in Bar for $350
John publi...