Displaying 20 results from an estimated 10000 matches similar to: "ActiveRecord question"
2006 Jul 28
2
ActiveRecord design question
Hi everyone, I have a small design question.
My app has the classical ''User'' table. The problem is that I will
probably have a lot of user set options. I did not want to add 20-30
fields to the user table so I created a user_options table:
===============================
class User < ActiveRecord::Base
has_many :user_options
end
===============================
class
2006 Jul 23
4
Newbie question about .rhtml
Hi everyone, coming from PHP something in the .rhtml files has been
confusing the heck out of me.
Why does this work?
<% for header in @all_headers %>
<%= header.subject %>
<% end %>
and both of these don''t work
<% for header in @all_headers
puts header.subject
end %>
---------------------------------------
<%= for header in @all_headers
puts
2006 Jul 02
2
Problems implementing a N:M table that contains actual data
Hi everyone,
I''m currently finishing the planning phase of a small project I want to
create. I read a bunch of tutorials about ActiveRecord and the
different way to link your "tables" with belongs_to, has_many,
has_and_belong_..., etc... However I''m stillnot sure if what I''m trying
to do will work *well* with ActiveRecord.
So enough talk,
2009 Oct 05
0
ActiveRecord Polymorphic Inheritance
I am using RoR ActiveRecord polymorphic inheritance and was wondering
if it''s possible to access the base class'' association methods in the
invocation of either to_xml or to_json without having to depict the
base class data in the serialized string. Here are my classes:
# base class
class Asset < ActiveRecord::Base
belongs_to :resource, :polymorphic => true
2006 Aug 09
2
has_many through delete issue
I have the following many-to-many relationships defined in my model code
to model a many to many relationship between Media and PriceCode with
Price being the association table:
class Media < ActiveRecord::Base
has_many :prices
has_many :price_codes, :through => :prices
end
class Price < ActiveRecord::Base
belongs_to :media
belongs_to :price_code
end
class PriceCode <
2010 Nov 16
3
Can't do a nested define. What are my options?
I''m trying to create a directory structure from 2 arrays. First array
is the "outter", second is the "inner". For each "outter", I''d like to
loop through each "inner".
Below is sort of what I''m trying to do. In the real world, the
$sys_name and $mounts vars will be parsed from yaml and will be
dynamic. In the example I''ve
2006 Aug 19
3
Activerecord validation problems
Hi everyone,
I''m having trouble validating a model. The corresponding table has some
boolean columns:
create_table :permissions do |t|
t.column :project_id, :integer, :null => false
t.column :group_id, :integer, :null => false
t.column :read, :boolean, :null => false, :default => false
t.column :write, :boolean, :null => false, :default =>
2008 Apr 21
1
Urgent ActiveRecord has_many Problem - Please Help
Hi Guys,
I''ve been looking everywhere for an answer to this but so far without
success.
I have three models:
1) employees
has_many :memberships
has_many :projects, :through => :membership
2) projects
has_many :memberships
has_many :employees, :through => :membership
3) membership
belongs_to :employees
belongs_to :projects
Membership is used to join employees
2006 Apr 07
0
Custom Non-ActiveRecord Classes or not...
Say I want to gather info from various Models... Files, Folders, and put
them into a ''display'' Object DisplayFilesystem that will standarize the
info from both tables (for display only)...
Class DisplayFilesystem
attr_accessor :item_id, :name, :type, :description, :date
def initialize
@item_id = @name = @type = @description = @date = nil
end
end
So in the code side
2011 Jul 26
1
ActiveRecord has_many associations
Given the models Country, State, City and Person as follows.
class Country < ActiveRecord::Base
has_many :states
end
class State < ActiveRecord::Base
belongs_to :country
has_many :cities
end
class City < ActiveRecord::Base
belongs_to :state
has_many :people
end
class Person < ActiveRecord::Base
belongs_to :city
end
Is there any way that doesn''t allow to delete
2012 Sep 21
4
Good resource for the history of activerecord association method naming?
Someone asked me about the history of the method naming in activerecord and
I wasn''t sure where to point them. For example, there was early criticism
noted of has_and_belongs_to_many in this old post from 2005:
http://hans.fugal.net/blog/2005/10/03/habtm/
I was mentioning that many_to_many is not used because there are a few
different ways of doing that via has_many :through and
2006 Mar 21
3
Newbie - ActiveRecord relationships
So I''ve worked through Agile Web Development with Rails and I''m now
trying my first little app to get into the swing of things. Its a task
tracking app where people can create tasks and assign them to others,
and also log time against the tasks.
I''m having trouble working out the model relationships. This is what
I''ve got so far, but its not right as
2006 Jan 24
4
How to filter an activerecord find_all...
I have a nice hierarchical table structure like this:
divisions
has_many groups
groups
belongs_to division
has_many subgroups
subgroups
belongs_to group
has_many units
units
belongs_to subgroup
I have a report which is based on units, but i want to be able to filter
the units by which subgroup, or which group, or which division. I also
want to sort them by division.name,then group.name,
2010 Nov 11
5
ActiveRecord query
I have these sql code in postgresql
"SELECT * from convenios where id NOT IN
(SELECT convenio_id from solicituds where usuario_id=?"
but don''t find a way of used it in rails
except
find_by_sql.
There is a another way??
class Usuario < ActiveRecord::Base
belongs_to :persona
has_many :solicituds, :dependent => :destroy
has_many :convenios, :through =>
2006 Mar 21
0
Nested One-To-Many ActiveRecord Question
I have a set of one-to-many relationships, nested 4 deep. In other
words:
table_A has_many table_B,
table_B belongs_to table_A, has_many table C,
table_C belongs_to table_B, has_many table D,
table_D belongs_to table_C
Now, I want to to find on table_A, based on criteria in table_D, and
I want to paginate it. And I need fields from all four tables in the
result set.
Does anyone know
2006 Apr 19
2
Using Reflections to find out ActiveRecord class association
I want to find out what are the associations with another active record
class. So If my class is as below:
Class Component < ActiveRecord::Base
has_many :branches
end
class Branch < ActiveRecord::Base
belongs_to :component
end
and then I do
Component.reflections[:branches].active_record
I would expect that to be Branch but it is in fact Component.
The inspection of
2010 Mar 10
0
Rails ActiveRecord associations autosave option
I have the following associations.
class Document < ActiveRecord::Base
has_many :document_sections, :dependent => :destroy, :autosave => true
has_many :document_items, :through => :document_sections
end
class DocumentSection < ActiveRecord::Base
belongs_to :document
has_many :document_items, :dependent => :destroy, :autosave => true
end
class DocumentItem <
2006 Nov 04
0
ActiveRecord
I''m running into a bit of a ideological and functional problem with
ActiveRecord and would like to find out if some of these concerns are
valid. Hopefully someone here already knows the answer...
The concerns are that ActiveRecord has a lot of activity involving data
validation (validates_uniqueness_of, validates_associated) and model
definition (belongs_to, has_many, has_one).
2009 Apr 10
1
ActiveRecord question
Hello there, newbie speaking
Let''s say I have:
class Office
has_many :holidays #(just a list of dates when the office is closed)
has_many :doctors #doctors who work in the office
end
class Doctor
belongs_to :office
has_many :holidays #(additional dates when this doctor is not
available)
end
class Holiday (has a office_id, doctor_id and a date field)
end
From the app standpoint I
2011 Nov 02
2
Specify and validate requirements on an ActiveRecord association
Looking for some guidance/support on what feels like might not be an
uncommon use-case.
`User.has_many accounts`
`User.has_many payment_methods`
`Account.belongs_to :user`
`Account.belongs_to :payment_method`
`PaymentMethod.has_many :accounts`
There are lots of `Accounts`. When I (a `User`) want to assign
accounts to a `PaymentMethod`, I really don''t want to scope against
all of them,