Displaying 20 results from an estimated 20000 matches similar to: "Add extra data to objects in an instance variable?"
2008 Apr 23
0
self referential (n-n relationship) belongs many controller
Hi all,
I ve some troubles in my small acpplication (only 2 tables).
I want to follow up tasks but these tasks are linked to others tasks.
So I ve tried to do store the nn relationship in other table called
links
1st table : tasks
columns : id | infos neutral... (as title, description etc ...)
-----------------------------------------------------------------------------------
model :
class
2006 May 10
4
Single Table Inheritance problem
I have two tables I am using single table inheritance with: Page and
Item. "Page" has many "Items"; "Item" belongs to "Page".
Item Model:
class Item < ActiveRecord::Base
end
class Article < Item
belongs_to :page
end
Page Model:
class Page < ActiveRecord::Base
end
class Issue < Page
has_many :articles
end
In my controller, when I
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,
2007 Jul 29
1
Curious why this doesn't work. (has_many, belongs_to)
Two Models.
class Gm < ActiveRecord::Base
belongs_to :pool
# mode code here.
end
class Pool < ActiveRecord::Base
has_many :gms
# mode code here.
end
Testing code through the console.
>> gm_list.each{ | gm | puts " GM name: #{ gm.user_name } belongs to Pool: #{ gm.pool.pool_name } " }; nil
GM name: John belongs to Pool: RHP 07-08 Season - Career League
GM name:
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 May 05
0
Missing documentation for find_in_collection? Trying to drill down in a 4 level has_many association fails
I''ve been reading up in ActiveRecord::Associations and playing around
with my app via the console and found some interesting methods via
the code completion of IRB, but I have no idea how to use them and
can only find one hint in the API
http://api.rubyonrails.com/classes/ActiveRecord/Associations/
ClassMethods.html
It mentions here in the has many associations that if you use the
2006 Apr 24
5
Custom pagination
I am trying to paginate objects from a has_many/:through relationship
using Paginator.
current_user.things returns the objects that I''d like to paginate. For
testing, I tried to make it 1 item per page. I initialise the paginator
as follows:
@thing_pages = Paginator.new(self, current_user.things.count, 1,
@params[''page''])
I don''t know how to obtain
2005 Aug 04
1
Pagination and :include (eager associations)
I have tried to use eager association with pagination, but
the :include option is not supported:
Here''s the one-line pagination call without :include
@link_pages, @links = paginate :link, :per_page => 10, :order_by
=> sort_clause
and here the work around, using the "classic" method
# @link_pages = Paginator.new self, Link.count, 10,
2006 Mar 21
5
Order records based on number of children
Let''s say I have simple schema with two tables. The models are defined
like the folllowing:
class Parent < ActiveRecord::Base
has_many :children
end
class Child < ActiveRecord::Base
belongs_to :parent
end
Simple has_many relationship. Is there any way to order the results of
a Parent.find_all by the number of children the parent has? I can
sort with
sorted_parents =
2006 Jan 10
5
Select Tag and Associations
Hi there,
I''ve been working on this for awhile and have finally decided to ask
for a little guidance.I have a slight problem trying to save a
selection.
I have two models:
A "Posting" has_many "Categories", and a "Category" belongs_to one
"Posting". With that said, in the posting model I have "has_many
:categories" and within the
2005 Dec 27
0
How do I combine :finder_sql and :conditions to perform a sub-search on a custom has_many relationship?
I''m sure there''s something right under my nose that I''m missing.
I have two tables with two parallel one-to-many relationships. I wish
to use the :finder_sql parameter to essentially ''or'' the two foreign
keys.
What isn''t working for me is performing a ''sub-search''.
Let''s say the tables are "stores" and
2005 Dec 27
3
Trouble combining :has_many, :finder_sql and :conditions to create a sub-search
I''m sure there''s something right under my nose that I''m missing. I
have two tables with two parallel one-to-many relationships. I wish to
use the :finder_sql parameter to essentially ''or'' the two foreign
keys.
What isn''t working for me is performing a ''sub-search''.
Let''s say the tables are "stores" and
2012 May 04
0
Why does Rails only save the joiner record in one instance but not another?
Assuming we have User, Account, and Role models, and a User has_many
:accounts, through: :roles and vice-versa, with the following snippet Rails
automatically creates the Role (joiner) record, but with the snippet after
Rails will not. I think I''m misunderstanding how has_many through works, so
I would appreciate any insight into the subject.
def new
@account =
2006 May 31
3
class does not inherit (?) ActionRecord::Base
Hi. I''m a newbie at this, so please bear with me.
I have several classes which model several corresponding tables. All of
them seem to work except one. I have not made many modifications from
the scaffold templates. However, with one class, Log, all methods give
me the following type of error
NoMethodError in LogController#create
undefined method `save'' for
2006 Apr 09
1
select helper question
Hi there, I try to develop a medical application using ruby on rails.
There are many categories which can contain subcategories.
I defined the model like this:
class Category < ActiveRecord::Base
has_and_belongs_to_many :notes
belongs_to :parent_category, :class_name=>"Category",
:foreign_key=>"category_id"
has_many :sub_categories,
2006 Aug 15
2
Working with user data
I am a Rails newbie and I am trying to build a test site in which users
will have their own sets of data.
I understand how to manipulate shared data very well. Most of the Rails
examples out there seem to deal with such shared data. I am struggling
with the "best practice" method for a user to work with their own data
however (and not be able to view/edit other users''
2006 Jan 04
8
Trying to display data from two tables
Alrighty folks, I''m really trying here, and want to succeed with Ruby on
Rails.
I''m trying to display data that is linked from two tables using the
Active Record naming conventions, as described in Agile Web book.
The stripped-down basics;
Database
drop table if exists people;
CREATE TABLE `people` (
`id` int(6) NOT NULL auto_increment,
`lastname` varchar(30) NOT NULL,
2009 May 11
0
updating join table (HMT) with checkbox and extra fields
Hi,
I''ve been breaking my head over this thing with no success. Here is my
table layout -
class User < AR
has_many :memberships
has_many :groups, :through => :memberships
...
class Group < AR
has_many :memberships
has_many :users, :through => :memberships
...
class Membership < AR
belongs_to :user, :class_name => "User", :foreign_key =>
2006 Feb 22
3
Listing/Relationship Question
Hello,
I know this is probably super simple, but for some reason I just can''t get
it!
What I want to do is click on a post and display all the categories that the
post is in.
class Post < ActiveRecord::Base
has_many :categories
end
class Category < ActiveRecord::Base
belongs_to :post
end
...simple enough.
In the categories_controller I have this:
def list_all_categories
2006 Apr 26
2
Multiple Select example?
I''ve been trying to sort out a multiple select dropdown but haven''t
found any good examples - anyone know of any or perhaps could make a
suggestion [see below]
Model:
1. Task AR has_many users
2. User AR belongs_to task
login/password attributes
Controller:
View:
<%= collection_select("task", "users" , @users, "id", "login", {},