Re: [Rails] Re: Active Record Associations - best way to find all items assosciated with a specific company

2011-10-04 Thread Colin Law
On 4 October 2011 22:07, Jim Burgess wrote: > Many thanks for your quick help Colin. > That's a nice solution to the problem and it's also good to find out > what the best practice is. I am not sure I am confident that this is *best* practice, but it works for me. Others more experienced may wel

[Rails] Re: Active Record Associations - best way to find all items assosciated with a specific company

2011-10-04 Thread Jim Burgess
Many thanks for your quick help Colin. That's a nice solution to the problem and it's also good to find out what the best practice is. Jim -- 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 pos

[Rails] Re: Active Record associations performance

2009-10-14 Thread Ilan Berci
Anton Ivanov wrote: > Hi, > this (in class Project): > def copy(other_project) > other_project.issues.each do |other_issue| > self.issues << other_issue.copy > end > self.save > end > Not tested.. just thinking.. Get the link(associative) table that's used in the many to many associ

[Rails] Re: Active Record Associations and application outline advice

2009-08-18 Thread Marnen Laibow-Koser
Adam Akhtar wrote: > Hi again, thanks so much for your help i really appreciate it. I wanted > to write another association like you said before but there is no > Alphabet_Partner class to write it in. Its just a self reference to > Alphabet table. [...] You don't need an AlphabetPartner class

[Rails] Re: Active Record Associations and application outline advice

2009-08-18 Thread Adam Akhtar
Thanks again. Ok i know why your saying to have a consistent sorting method, its so as to avoid a duplicate situation i.e. if i always sort by the letter and id then i will always save as ab and not ba. If theres already an ab there and i have some validations i can avoid reading in another ab.

[Rails] Re: Active Record Associations and application outline advice

2009-08-18 Thread Adam Akhtar
Hi again, thanks so much for your help i really appreciate it. I wanted to write another association like you said before but there is no Alphabet_Partner class to write it in. Its just a self reference to Alphabet table. Alphabet_Partner is only defined in class Alphabet < ActiveRecord::Base

[Rails] Re: Active Record Associations and application outline advice

2009-08-18 Thread Marnen Laibow-Koser
Adam Akhtar wrote: > Thanks again. > Ok i know why your saying to have a consistent sorting method, its so as > to avoid a duplicate situation i.e. if i always sort by the letter and > id then i will always save as ab and not ba. If theres already an ab > there and i have some validations i can

[Rails] Re: Active Record Associations and application outline advice

2009-08-18 Thread Marnen Laibow-Koser
Adam Akhtar wrote: > > Marnen many thanks again for your help. You're welcome. > So if i sort them by their name then id, and I have A and B with ids 1 > and 2 respectively then in my pairing controller id do > @pairing = Pairing.new(params[:pairing]) > @pairing.save (Which would use the callb

[Rails] Re: Active Record Associations and application outline advice

2009-08-18 Thread Adam Akhtar
"So A has an Ingredient_Partner B" was a typo, should have read alphabet_partner -- 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 thi

[Rails] Re: Active Record Associations and application outline advice

2009-08-18 Thread Adam Akhtar
> No, I am saying you would *not* have to have two pairs. Rather, when > you construct a Pairing, pick an unambiguous way of sorting the two > Alphabet objects so that ab and ba will map to the same thing. For > example (untested): > > class Pairing < AR::B > before_create do > [...@

[Rails] Re: Active Record Associations and application outline advice

2009-08-18 Thread Marnen Laibow-Koser
Adam Akhtar wrote: [...] [...] >> Use a Pairing class with a polymorphic association. > > I thought polymorphic associations are used when you have several > different models which have the same relationship with anohter one. I.e. > You want to have comments associated with your models for Phot

[Rails] Re: Active Record Associations and application outline advice

2009-08-18 Thread Adam Akhtar
Hi Thanks for your reply and your suggestions. Im a bit confused, could you help clarify the following - >> Hi if i have one model say with objects for each letter of the alphabet >> e.g a,b,c ... x,y,z and i want to allow users to create there own >> favourite pairings of these e.g. >> >> ab,

[Rails] Re: Active Record Associations and application outline advice

2009-08-17 Thread Marnen Laibow-Koser
Adam Akhtar wrote: > Hi if i have one model say with objects for each letter of the alphabet > e.g a,b,c ... x,y,z and i want to allow users to create there own > favourite pairings of these e.g. > > ab, cd, ef, gp and allow them to discuss via comments on each pairing, > whats teh best way to mo

[Rails] Re: Active Record Associations

2009-02-11 Thread Julian Leviston
Why is a good question here. In other words, what are you going to do with the computers and users once You get them. Blog: http://random8.zenunit.com/ Learn rails: http://sensei.zenunit.com/ On 11/02/2009, at 4:42 AM, James Bond wrote: > > Rey wrote: >> If I understand correctly what yo

[Rails] Re: Active Record Associations

2009-02-11 Thread Julian Leviston
Oh by the way if you do that you'll end up with an array of arrays. Might not be what you want. Blog: http://random8.zenunit.com/ Learn rails: http://sensei.zenunit.com/ On 11/02/2009, at 11:50 PM, Sijo Kg wrote: > > Hi > > @users = User.find(:all,:conditions=> ['name LIKE ?', "James%"]) >

[Rails] Re: Active Record Associations

2009-02-11 Thread Julian Leviston
Or use has_many :through instead. Blog: http://random8.zenunit.com/ Learn rails: http://sensei.zenunit.com/ On 11/02/2009, at 11:50 PM, Sijo Kg wrote: > > Hi > > @users = User.find(:all,:conditions=> ['name LIKE ?', "James%"]) > @user_computers = [] > @users.each do |user| > @user_computers

[Rails] Re: Active Record Associations

2009-02-11 Thread James Bond
Sijo Kg wrote: I mean something like this: SELECT users.name, computers.name FROM users, OwnComputers, computers JOIN OwnComputers ON users.id = OwnComputers.users_id JOIN computers ON OwnComputers.computers_id = computers.id WHERE user.name LIKE "James%" -- Posted via http://www.ruby-forum.com

[Rails] Re: Active Record Associations

2009-02-11 Thread Sijo Kg
Hi @users = User.find(:all,:conditions=> ['name LIKE ?', "James%"]) @user_computers = [] @users.each do |user| @user_computers << user.computers end @user_computers now contains computers you need Sijo -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--

[Rails] Re: Active Record Associations

2009-02-11 Thread James Bond
> How can I find all users whose name is "James%" and their computers (not > mobiles)? > > User.find(:all, ??) Help ??? -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Group

[Rails] Re: Active Record Associations

2009-02-10 Thread James Bond
Rey wrote: > If I understand correctly what you need, a computer may belong to many > users and one user can have many computer, right? same for phones, I > assume. Yes > In this case, the relationship is :has_and_belongs_to_many, but you do How can I find all users whose name is "James%" a

[Rails] Re: Active Record Associations

2009-02-10 Thread Rey9999
If I understand correctly what you need, a computer may belong to many users and one user can have many computer, right? same for phones, I assume. In this case, the relationship is :has_and_belongs_to_many, but you do not need the classes OwnComputer and the other one. you just need two tables (

[Rails] Re: active record associations

2008-11-06 Thread Franz
The dirty object feature doesn't work for has_many associations. I solved the problem by wrapping a transaction around the code to revert the changes in the database. I kinda wish, ror could keep the functionality between regular fields and association fields consistent to avoid confusion. kind

[Rails] Re: active record associations

2008-11-06 Thread JL Smith
This sounds like the dirty object feature of Rails 2.1 would work great: http://ryandaigle.com/articles/2008/3/31/what-s-new-in-edge-rails-dirty-objects Maybe even try to utilize some callback methods so you can capture and display the changes to the user: http://railsforum.com/viewtopic.php?id=2