I have Ruser and Bag models. I''m using Ruser instead of User because I know "user" create problems with a postgresql database. Bags must be delivered to Ruser so I need to know when one or more bags are delivered. I create these associations: class Ruser < ActiveRecord::Base has_many :deliveries has_many :bags, :through => :deliveries class Bag < ActiveRecord::Base has_many :deliveries has_many :rusers, :through => :deliveries class Delivery < ActiveRecord::Base belongs_to :ruser belongs_to :bag Ruser and Bag are already populated. Delivery has delivered_at attribute. Now I want delivery 3 bags to ruser. I can do bags=Bags.all user=Ruser.find(params[:id]) delivery = user.deliveries.create(:delivered_at => Date.today). But I can''t do delivery.bags << bags. I think that could be some mistakes in my associations. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jan 24, 12:48 pm, Mauro <mrsan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Now I want delivery 3 bags to ruser. > I can do > bags=Bags.all > user=Ruser.find(params[:id]) > delivery = user.deliveries.create(:delivered_at => Date.today). > But I can''t do delivery.bags << bags. > I think that could be some mistakes in my associations.You''ve written that deliver belongs_to bag (ie there is at most one bag for a delivery). With the way your models currently exist, you''d need to create one delivery for each bag. Fred -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Msan Msan wrote in post #977110:> I have Ruser and Bag models. > I''m using Ruser instead of User because I know "user" create problems > with a postgresql database.You may "know" it, but it ain''t true. I use User models in PostgreSQL all the time.> Bags must be delivered to Ruser so I need to know when one or more > bags are delivered. > I create these associations: > > class Ruser < ActiveRecord::Base > has_many :deliveries > has_many :bags, :through => :deliveries > > class Bag < ActiveRecord::Base > has_many :deliveries > has_many :rusers, :through => :deliveries > > class Delivery < ActiveRecord::Base > belongs_to :ruser > belongs_to :bag > > Ruser and Bag are already populated. > Delivery has delivered_at attribute. > > Now I want delivery 3 bags to ruser. > I can do > bags=Bags.all > user=Ruser.find(params[:id]) > delivery = user.deliveries.create(:delivered_at => Date.today). > But I can''t do delivery.bags << bags. > I think that could be some mistakes in my associations.Of course you can''t do delivery.bags . You''ve specified Delivery belongs_to :bag, which means that there''s only one bag for a delivery to be associated with. Perhaps you wanted Delivery has_many :bags. You probably also wanted Bag belongs_to :delivery : how can one bag be part of several deliveries? I think you need to analyze the relationships between your models a little better. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 24 January 2011 15:33, Marnen Laibow-Koser <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Msan Msan wrote in post #977110: >> I have Ruser and Bag models. >> I''m using Ruser instead of User because I know "user" create problems >> with a postgresql database. > > You may "know" it, but it ain''t true. I use User models in PostgreSQL > all the time.That''s because rails translate User in users table. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 24 January 2011 16:04, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 24 January 2011 15:33, Marnen Laibow-Koser <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> Msan Msan wrote in post #977110: >>> I have Ruser and Bag models. >>> I''m using Ruser instead of User because I know "user" create problems >>> with a postgresql database. >> >> You may "know" it, but it ain''t true. I use User models in PostgreSQL >> all the time. > > That''s because rails translate User in users table.What do you mean by that, I do not understand. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Msan Msan wrote in post #977159:> On 24 January 2011 15:33, Marnen Laibow-Koser <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> > wrote: >> Msan Msan wrote in post #977110: >>> I have Ruser and Bag models. >>> I''m using Ruser instead of User because I know "user" create problems >>> with a postgresql database. >> >> You may "know" it, but it ain''t true. I use User models in PostgreSQL >> all the time. > > That''s because rails translate User in users table.And your point is...? Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 24 January 2011 17:21, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 24 January 2011 16:04, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> On 24 January 2011 15:33, Marnen Laibow-Koser <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >>> Msan Msan wrote in post #977110: >>>> I have Ruser and Bag models. >>>> I''m using Ruser instead of User because I know "user" create problems >>>> with a postgresql database. >>> >>> You may "know" it, but it ain''t true. I use User models in PostgreSQL >>> all the time. >> >> That''s because rails translate User in users table. > > What do you mean by that, I do not understand.nothing important, I work with other frameworks, like grails, that do not pluralized the model name when creating the table so I used not to use "user". -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 24 January 2011 19:03, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 24 January 2011 17:21, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> On 24 January 2011 16:04, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> On 24 January 2011 15:33, Marnen Laibow-Koser <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >>>> Msan Msan wrote in post #977110: >>>>> I have Ruser and Bag models. >>>>> I''m using Ruser instead of User because I know "user" create problems >>>>> with a postgresql database. >>>> >>>> You may "know" it, but it ain''t true. I use User models in PostgreSQL >>>> all the time. >>> >>> That''s because rails translate User in users table. >> >> What do you mean by that, I do not understand. > > nothing important, I work with other frameworks, like grails, that do > not pluralized > the model name when creating the table so I used not to use "user".You have still not explained why you are not using a class name User and table name users. You appeared to suggest that this is not possible when using PostgreSQL. Colin Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 24 January 2011 21:42, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 24 January 2011 19:03, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> On 24 January 2011 17:21, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >>> On 24 January 2011 16:04, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>>> On 24 January 2011 15:33, Marnen Laibow-Koser <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >>>>> Msan Msan wrote in post #977110: >>>>>> I have Ruser and Bag models. >>>>>> I''m using Ruser instead of User because I know "user" create problems >>>>>> with a postgresql database. >>>>> >>>>> You may "know" it, but it ain''t true. I use User models in PostgreSQL >>>>> all the time. >>>> >>>> That''s because rails translate User in users table. >>> >>> What do you mean by that, I do not understand. >> >> nothing important, I work with other frameworks, like grails, that do >> not pluralized >> the model name when creating the table so I used not to use "user". > > You have still not explained why you are not using a class name User > and table name users. You appeared to suggest that this is not > possible when using PostgreSQL.I was confused thinking about grails. With rails "User" can be used, with grails don''t. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jan 24, 2011, at 4:17 PM, Mauro wrote:> I was confused thinking about grails. > With rails "User" can be used, with grails don''t.Why not? I have Grails apps with a User domain class that work just fine. Although as a best practice in the Grails world you want to package your domain classes, so it''ll probably have a table like com.myco.user. But I''ve done quick demo''s in Grails with an unpackaged User class with no problem at all. Best Wishes, Peter -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 24 January 2011 22:44, Peter Bell <peter-AS9tOuWgs4cAvxtiuMwx3w@public.gmane.org> wrote:> > On Jan 24, 2011, at 4:17 PM, Mauro wrote: >> I was confused thinking about grails. >> With rails "User" can be used, with grails don''t. > > Why not? I have Grails apps with a User domain class that work just fine. Although as a best practice in the Grails world you want to package your domain classes, so it''ll probably have a table like com.myco.user. > > But I''ve done quick demo''s in Grails with an unpackaged User class with no problem at all.It''s an OT but the name tables that grails creates are not like you said. If you create a domain class com.myco.user the table that grails create is simply user and postgres doesn''t like to have a table called user. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.