Is it me or is my model getting the created_at from the wrong model! I have a HABTM relationship between Problems and Tags. In one of my controller I do the following: def view @tag = Tag.find_by_name @params[:id] end In my view I do this: <% @tag.problems.each do |problem| %> ... <%= problem.created_at %> ... <% end %> Now, how come the created_at is being taken from the HABTM relationship instead of the problem table itself? This does not make sense to me. How would I get created_at from Problem table instead of problems_tag table? Thanks for your help? John Kopanas http://www.kopanas.com ===========================================================http://www.soen.info - Index of online software engineering knowledge http://www.cusec.net - Canadian University Software Engineering Conference http://www.soenlive.com - Presentations from CUSEC
From the documentation for has_and_belongs_to_many: Any additional fields added to the join table will be placed as attributes when pulling records out through has_and_belongs_to_many associations. Records returned from join tables with additional attributes will be marked as ReadOnly (because we can?t save changes to the additional attrbutes). It?s strongly recommended that you upgrade any associations with attributes to a real join model (see introduction). Pete Yandell http://9cays.com On 11/06/2006, at 5:56 AM, John Kopanas wrote:> Is it me or is my model getting the created_at from the wrong model! > > I have a HABTM relationship between Problems and Tags. In one of > my controller I do the following: > > def view > @tag = Tag.find_by_name @params[:id] > end > > In my view I do this: > > <% @tag.problems.each do |problem| %> > ... > <%= problem.created_at %> > ... > <% end %> > > Now, how come the created_at is being taken from the HABTM > relationship instead of the problem table itself? This does not > make sense to me. How would I get created_at from Problem table > instead of problems_tag table? > > Thanks for your help? > > > John Kopanas > http://www.kopanas.com > > > ===========================================================> http://www.soen.info - Index of online software engineering knowledge > http://www.cusec.net - Canadian University Software Engineering > Conference > http://www.soenlive.com - Presentations from CUSEC > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
I am not sure this answers my question. Does that mean that created_at was overode by the join_table.created_at and their is nothing I can do about that? HABTM must be more sophisticated then that no? On 11-Jun-06, at 9:58 PM, Pete Yandell wrote:> From the documentation for has_and_belongs_to_many: > > Any additional fields added to the join table will be placed as > attributes when pulling records out through has_and_belongs_to_many > associations. Records returned from join tables with additional > attributes will be marked as ReadOnly (because we can?t save > changes to the additional attrbutes). It?s strongly recommended > that you upgrade any associations with attributes to a real join > model (see introduction). > > Pete Yandell > http://9cays.com > > On 11/06/2006, at 5:56 AM, John Kopanas wrote: > >> Is it me or is my model getting the created_at from the wrong model! >> >> I have a HABTM relationship between Problems and Tags. In one of >> my controller I do the following: >> >> def view >> @tag = Tag.find_by_name @params[:id] >> end >> >> In my view I do this: >> >> <% @tag.problems.each do |problem| %> >> ... >> <%= problem.created_at %> >> ... >> <% end %> >> >> Now, how come the created_at is being taken from the HABTM >> relationship instead of the problem table itself? This does not >> make sense to me. How would I get created_at from Problem table >> instead of problems_tag table? >> >> Thanks for your help? >> >> >> John Kopanas >> http://www.kopanas.com >> >> >> ===========================================================>> http://www.soen.info - Index of online software engineering knowledge >> http://www.cusec.net - Canadian University Software Engineering >> Conference >> http://www.soenlive.com - Presentations from CUSEC >> >> >> _______________________________________________ >> Rails mailing list >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/railsJohn Kopanas http://www.kopanas.com ===========================================================http://www.soen.info - Index of online software engineering knowledge http://www.cusec.net - Canadian University Software Engineering Conference http://www.soenlive.com - Presentations from CUSEC
On 12/06/2006, at 3:45 PM, John Kopanas wrote:> I am not sure this answers my question. Does that mean that > created_at was overode by the join_table.created_at and their is > nothing I can do about that?Yes. Any attributes on a join table appear in records you get when querying a HABTM relationship that uses that join table.> HABTM must be more sophisticated then that no?HABTM is not more sophisticated than that, which is why "It?s strongly recommended that you upgrade any associations with attributes to a real join model". See the section on "Association Join Models" in the ActiveRecord::Associations::ClassMethods documentation. Pete Yandell http://9cays.com> On 11-Jun-06, at 9:58 PM, Pete Yandell wrote: > >> From the documentation for has_and_belongs_to_many: >> >> Any additional fields added to the join table will be placed as >> attributes when pulling records out through >> has_and_belongs_to_many associations. Records returned from join >> tables with additional attributes will be marked as ReadOnly >> (because we can?t save changes to the additional attrbutes). It?s >> strongly recommended that you upgrade any associations with >> attributes to a real join model (see introduction). >> >> Pete Yandell >> http://9cays.com >> >> On 11/06/2006, at 5:56 AM, John Kopanas wrote: >> >>> Is it me or is my model getting the created_at from the wrong model! >>> >>> I have a HABTM relationship between Problems and Tags. In one of >>> my controller I do the following: >>> >>> def view >>> @tag = Tag.find_by_name @params[:id] >>> end >>> >>> In my view I do this: >>> >>> <% @tag.problems.each do |problem| %> >>> ... >>> <%= problem.created_at %> >>> ... >>> <% end %> >>> >>> Now, how come the created_at is being taken from the HABTM >>> relationship instead of the problem table itself? This does not >>> make sense to me. How would I get created_at from Problem table >>> instead of problems_tag table? >>> >>> Thanks for your help? >>> >>> >>> John Kopanas >>> http://www.kopanas.com >>> >>> >>> ===========================================================>>> http://www.soen.info - Index of online software engineering >>> knowledge >>> http://www.cusec.net - Canadian University Software Engineering >>> Conference >>> http://www.soenlive.com - Presentations from CUSEC >>> >>> >>> _______________________________________________ >>> Rails mailing list >>> Rails@lists.rubyonrails.org >>> http://lists.rubyonrails.org/mailman/listinfo/rails >> >> _______________________________________________ >> Rails mailing list >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails > > > John Kopanas > http://www.kopanas.com > > > ===========================================================> http://www.soen.info - Index of online software engineering knowledge > http://www.cusec.net - Canadian University Software Engineering > Conference > http://www.soenlive.com - Presentations from CUSEC > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails