I have a rails query like:
@user = User.find_by_username(params[:search], :include => [:user_similars])
Models: user (has_many :user_similars), user_similar (belongs_to :user)
The user_similars mysql table has a "user_id" field as a foreign key, but I don't want :include to join on that for this instance. I'd like to join on...
Many databases have a hidden primary key column. MySQL implements this as _rowid. In MySQL's case it is really a pointer to a previously defined primary key column. However in other databases (in my case, Informix), this column is independent of a deliberately defined primary key. The database which I'm coding for was designed mostly...
I'm in the process of replacing ActiveRecord with DataMapper in one of my apps. Since there aren't any authentication solutions that are compatable with DataMapper, I'm thinking that I could use ActiveRecord just for user authentication, and then use DataMapper everywhere else. I'd like to have both ORMs interacting with the same databas...
I'm writing a simpler version of phpMyAdmin in Rails; this web app will run on a web server (where users will be able to indicate the database name, hostname, username, password, and port number of one of the database servers running on the same network). The user will then be connected to that machine and will be able to use the UI to a...
Hello,
I'm using Ruby on Rails/ActiveRecord and am having trouble with an ActiveRecord#find call. I'm storing in the database a serialized array of recently viewed documents IDs. The IDs are stored in descending order of when they were last viewed, so the most recently viewed document ID is first in the array. The array includes 10 I...
Hi,
I've 2 models
class Room < ActiveRecord::Base
has_many :people
accepts_nested_attributes_for :people, :reject_if => lambda { |a| a[:person_id].blank? }, :allow_destroy => true
end
class Person < ActiveRecord::Base
belongs_to :room
end
In '/rooms/new' form I've a select tag containing all Person + an 'other' option tag that...
My question is somewhat complicated, but bear with me. My project has a number of models: User, Program, and Team. Users belong to multiple Programs. Programs have multiple teams, but Teams belong to one program. For each Program a User belongs to, he can belong to multiple Teams. (Think of this in an athletic context where users ar...
in my rails app, I have an Organization model, with a reference to a User, which I want to be able to access via organization_instance.adminstrator. I'm not sure how to accomplish this using the belongs_to method.
...
Rails is great that it will support timezone overall in the application with Time.zone. I need to be able to support the timezone a user selects for a record. The user will be able to select date, time, and timezone for the record and I would like all calculations to be done with respect to the user selected timezone.
My question is wha...
We have a medium size Java application that needs some refactoring.
We are considering migrating towards JRuby on Rails. Mainly because of the productivity that Ruby on Rails offers and for the many existing plugins that will reimplement the web logic.
However a large part of the application should stay in Java, we do not want to rewri...
I am developing a complex form that updates several records of one model at once, whilst simultaneously updating an associated model. It looks a bit like this:
class Sport
has_one :photo
end
class Photo
belongs_to :sport
acts_as_fleximage
end
class Page
# the page is not related to either of the previous models
end
Just for ...
I'm working on a little side project. I've got a large SQL query expression, 30+ lines, that I wish to use in my project. This app needs to provide read-only access to the database through these queries.
There are so many data layer choices. nHibernate, Entity Framework, LINQ to SQL, Datasets, Castle ActiveRecord... others I can't na...
I have a rails model with a hashed password field in it (surprise, surprise), which after some manipulation, is 40 characters long. I generate a user in script/console and it appears as follows:
#<User id: 1, firstname: "true", lastname: "false", username: "chaines51", hashed_password: "2Gr0GWvPunB3x5jomRTSTZJRIelC2RW103d7f3db">
I the...
As seen in comment_controller.rb:
def create
@comment = Comment.new(params[:comment])
@comment.save
end
Im assuming that this is SQL injection-unsafe. But what is the correct way of doing it?.. All the examples on the net deal with finds.
...
Is it possible to return an entity using a projection query?
I've successfully done it with a SQL query (see below), but can't find how to do it with a projection query.
Dim sql As String = "SELECT {a.*}, {b.*} FROM a LEFT OUTER JOIN b ON a.pk = b.fk")
' Convert SQL results into entities {a} and {b}
Dim query As IQuery = session.Creat...
Given the following models:
class Room < ActiveRecord::Base
has_many :contracts
end
class Contracts < ActiveRecord::Base
# columns
# start_date Date
# end_date Date
belongs_to :room
end
The contracts of one room are not overlapping. My question is, how i am be able to find gaps between contracts. An Example:
room = Room...
I am trying to do the following in a Ruby on Rails project:
class FoodItem < ActiveRecord::Base
has_and_belongs_to_many :food_categories
has_many :places, :through => :food_categories
end
class FoodCategory < ActiveRecord::Base
has_and_belongs_to_many :food_items
belongs_to :place
end
class Place < ActiveRecord::Base
has_m...
I have a model Article, that has_many Revisions. Revisions have a variety of columns storing all the information about the Article. The Article also belongs_to a current_revision, which is the primary key of the Revision that is currently selected. Each Revision is never changed after being created.
When a user goes to edit an Articl...
I have a data model involving Users and Awards, and joined by a user_awards table.
class User < ActiveRecord::Base
:has_many :user_awards
:has_many :awards, :through => :user_awards # awards the user has won
end
class Award < ActiveRecord::Base
:has_many :user_awards
:has_many :users, :through => :user_awards
end
I'd like th...