Displaying 20 results from an estimated 11000 matches similar to: "ActiveRecord design question"
2006 Jul 29
0
ActiveRecord question
Hi everyone,
I am having the following problem: I have a ''User'' model and a
''User_option'' model (user has_many user_options & user_options
belongs_to user).
Now the user_option table (and model) consist mostly of a key & value
fields, and I would like to be able to reference them like an
associative array
instead of a collection. Here is what I
2006 May 11
6
ActiveRecord associations
Can someone clarify this for me? Suppose I have two tables like:
class Company < ActiveRecord::Base
belongs_to :category
end
class Category < ActiveRecord::Base
has_many :companies
end
I understand that the belongs_to causes related companies to be read
from the db when I ask for a category. I suspect SQL something like
select * from categories, companies
where category.id
2008 Apr 11
2
Validating an ActiveRecord object and its has_many :through associations
Considering an object with several has_many :through => associations,
what is the ''best'' way to handle validations?
As an example:
class Student < ActiveRecord::Base
# some attrbutes like
# :name
# :grade
# relationships
has_many :students_assignment, :dependent => :destroy
has_many :assignments, :through => :students_assignment
has_many
2006 Apr 14
1
ActiveRecord and multiple associations
Hello,
I have a Company that has_and_belongs_to_many Persons. A Person
has_many Emails. I want to display each Person''s Email for each
Company, so I try this:
companies = Company.find(:all)
for company in companies
persons = company.persons
for person in persons
puts person.email
end
end
Unfortunately, this doesn''t work correctly. Let''s say the id of
2010 Jul 08
10
Asterisk Crashes - Segmentation Fault
Hello Team,
I was looking for audio conferencing solution where i got Web-meetme.
I had installed Asterisk 1.6.2.9 on Centos 5.4. Its perfecting working
fine. I tried using Meetme even meetme app is working perfectly fine.
I installed Webmeetme 4.0 and integrated with my asterisk. When i try to
dial the conference number it take me to an IVR wherein it asks for the
conference number. The time i
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
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
2005 Dec 12
2
How to use arbitrary relationships in Activerecord
How can I ask ActiveRecord to make it''s "has_many" code to work on some
arbitrary relationship between two tables? ie neither field is a primary key
The situation is that I am writing a Postfix management application and
one of the tables to manage is the "alias" table. My primary key in the
"mailbox" table is "id", but the alias table is just
2006 Jun 04
2
activerecord table help please
Hi everyone. I''m trying to figure out how to implement site-wide
tagging for my website. I have a rails-based weblog that supports
tagging posts. There''s a has_and_belongs_to_many relationship between
posts and tags. I''d like to now reuse those tags for tagging links as
well. Where I have a posts_tags table with post_id and tag_id fields,
I''d like to
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,
2007 Feb 04
2
Per activerecord object callbacks (aka: should I have gone to bed hours ago?)
First of all, I should have gone to bed a long time, so please be
forgiving with regards to what will follow :)
So I''ve been working all day on a rails project that needs to go out
soon, and I thought I would try to refactor a has_many relationship to
a has_and_belongs_to_many relationship (using has_many :through).
However, I then realized that I would loose a lot of the simple beauty
2007 May 22
3
BDD screenscast
I posted a quick screencast demonstrating some BDD with RSpec yesterday:
http://wincent.com/a/about/wincent/weblog/archives/2007/05/
behaviourdriven.php
I''m a C/Objective-C programmer who knows a bit of Ruby, almost
nothing about Rails, and in BDD I can really only claim "new but
interested" status.
It''s not scripted, it''s totally improvised and
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,
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 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 =>
2010 Oct 04
2
newbie q on activerecord - has_one and has_many on same table?
Hi I have a table where I need to identify one of the children as the
"prime" child.
So, its like:
Parent
has_many :Child
has_one: Child :as :prime_child (?)
or something like that? Do I put something like prime_child_id in the
Parent table?
Thanks.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this
2007 Aug 02
4
ActiveRecord Limitation (Advance)
Or is it ?
Need to be able to :-
@search =
Form.find(:all, :include=>[:form_type, :form_type_items], :conditions=>....)
I need in the Form model a :form_type_items, the question is, what is
the relationship type?
Current Models:-
Form
belongs_to :form_type
FormType
has_many :form_types
has_many :form_type_items
FormTypeItem
Belongs_to :form_type
Form
----------------
| id |
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
2008 Apr 11
1
Multi-user multi-company design
I am working on a site which tracks "ferms" (read: widgets)... each
ferm belongs to one company, one company can have many ferms.
One company can also have many users with different access priveliges,
and company administrators would invite other users to access the
company''s site.
Also, one user can belong to different companies and perhaps have
different access at each
2010 Jul 14
1
ActiveRecord::Observer, update_all and has_many
Hi,
I''m using an ActiveRecord::Observer to log users changing data in my
application. However, I''ve noted that adding an item to a has_many
relationship gets logged, but removing the item does not. That is:
@product.users << user
is logged, but:
@product.users.delete(user)
is not.
I''ve dug into ActiveRecord and found that the underlying issue is that
the