Paulo Abreu
2006-Jul-14 18:32 UTC
[Rails] Get a collection through ActiveRecord for using with option_groups_from_collection_for_select
Hello, I am having some difficulties with ActiveRecord. What I want to do is to get a collection of SubjectGroups for using with option_groups_from_collection_for_select My Code: =======================================class Subject < ActiveRecord::Base has_and_belongs_to_many :users belongs_to :subject_group end class SubjectGroup < ActiveRecord::Base has_many :subjects end @subjects= Subject.find(:all, :include => :subject_group) @groups= SubjectGroup.find(:all, :include => :subjects) The first find instruction runs just fine, the second gives me the following error: You have a nil object when you didn''t expect it!, The error occurred while evaluating nil.loaded I was expecting a SubjectGroup collection with all Subjects associated. In both cases I saw the generated queries through logs and returns the same query result. Thank you for your attention, Paulo Abreu
pama@netcabo.pt
2006-Jul-14 22:57 UTC
[Rails] Get a collection through ActiveRecord for using with option_groups_from_collection_for_select
Hello, I am having some difficulties with ActiveRecord. What I want to do is to get a collection of SubjectGroups for using with option_groups_from_collection_for_select My Code: =======================================class Subject < ActiveRecord::Base has_and_belongs_to_many :users belongs_to :subject_group end class SubjectGroup < ActiveRecord::Base has_many :subjects end @subjects= Subject.find(:all, :include => :subject_group) @groups= SubjectGroup.find(:all, :include => :subjects) The first find instruction runs just fine, the second gives me the following error: You have a nil object when you didn''t expect it!, The error occurred while evaluating nil.loaded I was expecting a SubjectGroup collection with all Subjects associated. In both cases I saw the generated queries through logs and returns the same query result. Thank you for your attention, Paulo Abreu
Paulo Abreu
2006-Jul-15 09:46 UTC
[Rails] Get a collection through ActiveRecord for using with option_groups_from_collection_for_select
Hello, I am having some difficulties with ActiveRecord. What I want to do is to get a collection of SubjectGroups for using with option_groups_from_collection_for_select My Code: =======================================class Subject < ActiveRecord::Base has_and_belongs_to_many :users belongs_to :subject_group end class SubjectGroup < ActiveRecord::Base has_many :subjects end @subjects= Subject.find(:all, :include => :subject_group) @groups= SubjectGroup.find(:all, :include => :subjects) The first find instruction runs just fine, the second gives me the following error: You have a nil object when you didn''t expect it!, The error occurred while evaluating nil.loaded I was expecting a SubjectGroup collection with all Subjects associated. In both cases I saw the generated queries through logs and returns the same query result. Thank you for your attention, Paulo Abreu
Mark Reginald James
2006-Jul-15 13:21 UTC
[Rails] Re: Get a collection through ActiveRecord for using with option_groups_from_collection_for_select
Paulo Abreu wrote:> class SubjectGroup < ActiveRecord::Base > has_many :subjects > end > > @subjects= Subject.find(:all, :include => :subject_group) > @groups= SubjectGroup.find(:all, :include => :subjects) > > The first find instruction runs just fine, the second gives me the > following error: > > You have a nil object when you didn''t expect it!, The error occurred > while evaluating nil.loadedIs that the entire code of your SubjectGroup model, or have you also defined your own "subjects" method within it? -- We develop, watch us RoR, in numbers too big to ignore.
Paulo Abreu
2006-Jul-15 15:11 UTC
[Rails] Re: Get a collection through ActiveRecord for using with option_groups_from_collection_for_select
On 7/15/06, Mark Reginald James <mrj@bigpond.net.au> wrote:> Paulo Abreu wrote: > > > class SubjectGroup < ActiveRecord::Base > > has_many :subjects > > end > > > > @subjects= Subject.find(:all, :include => :subject_group) > > @groups= SubjectGroup.find(:all, :include => :subjects) > > > > The first find instruction runs just fine, the second gives me the > > following error: > > > > You have a nil object when you didn''t expect it!, The error occurred > > while evaluating nil.loaded > > Is that the entire code of your SubjectGroup model, or have you also > defined your own "subjects" method within it? >The idia is to add my own methods for option_groups_from_collection_for_select, however I am not able to make this search. if I remove :include => :subjects it just works. In the IRC channel someone told me that I have a Subject with a subject_group_id that refers to a subject_group that doesnt exist, but I already verified that. Paulo Abreu
Paulo Abreu
2006-Jul-15 15:13 UTC
[Rails] Re: Get a collection through ActiveRecord for using with option_groups_from_collection_for_select
On 7/15/06, Mark Reginald James <mrj@bigpond.net.au> wrote:> Paulo Abreu wrote: > > > class SubjectGroup < ActiveRecord::Base > > has_many :subjects > > end > > > > @subjects= Subject.find(:all, :include => :subject_group) > > @groups= SubjectGroup.find(:all, :include => :subjects) > > > > The first find instruction runs just fine, the second gives me the > > following error: > > > > You have a nil object when you didn''t expect it!, The error occurred > > while evaluating nil.loaded > > Is that the entire code of your SubjectGroup model, or have you also > defined your own "subjects" method within it? >Oh sorry, I did not answer to your question. Is the entire code, no methods added yet. Paulo Abreu
Paulo Abreu
2006-Jul-15 16:55 UTC
[Rails] Re: Get a collection through ActiveRecord for using with option_groups_from_collection_for_select
> > Oh sorry, I did not answer to your question. Is the entire code, no > methods added yet.Oh god, I think I need to sleep :| in fact I had two member functions, that was the problem. Paulo Abreu.
Possibly Parallel Threads
- Mrelation does not exists
- option_groups_from_collection_for_select with a ActiveRecord::Base single object
- [PATCH] option_groups_from_collection_for_select should produce an HTML-safe string
- Multiple lattice plots on a page: aligning x-axes vertically
- Using two select elements (master - slave)