How to update a table which is connected with joins

hi all there are two tables Student and Batch in there model i have
has_and_belongs_to_many :graduated_batches, :class_name => ‘Batch’,
:join_table => ‘batch_students’ in Student table and
has_and_belongs_to_many :graduated_students, :class_name => ‘Student’,
:join_table => ‘batch_students’ in Batch table
which are connected to a table called “batch_students”
i have added a new column to batch_students table and i want to update
the
value in batch_students table. How can i update values in batch_students
table where there is no model for that table so that i can update
directly.how to update table which is in joins.

thanks in advance

On 12 June 2012 10:31, honey ruby [email protected] wrote:

hi all there are two tables Student and Batch in there model i have
has_and_belongs_to_many :graduated_batches, :class_name => ‘Batch’,
:join_table => ‘batch_students’ in Student table
i have added a new column to batch_students table and i want to update the
value in batch_students table. How can i update values in batch_students
table where there is no model for that table so that i can update
directly.how to update table which is in joins.

Sounds like you want to change those habtm relationships to “has_many
:through => :batch_students”

no with our changing the relationship can i update values.

thanks in advance

hi all help me out guys

thanks in advance

On Tue, Jun 12, 2012 at 3:07 PM, hanish jadala

How about:

http://abdul-barek-rails.blogspot.com/2009/12/how-to-execute-sql-query-in-rails.html

I didn’t tried it, but you may probably write Students.execute(‘update
anytable set …’)

by
TheR

thanks for your reply guys. hi Michael P. i can not change my
relationship because i have used in many other places if i change
relationship i have to make more changes in my app that is y i can not
change my relationship.

thanks in advance

On 13 June 2012 10:20, hanish jadala [email protected] wrote:

hi Michael P. i can not change my
relationship because i have used in many other places if i change
relationship i have to make more changes in my app that is y i can not
change my relationship.

So instead of doing a refactor to support the new functionality you
want (a moderately fiddly job to change “many other places” - but an
opportunity to DRY them up…), you’re going to plan to bodge in
something that will make it practically impossible to ever refactor
this area of code in the future. This will make any future
functionality changes in this area an absolute nightmare.

Google “technical debt”.

On 13 June 2012 08:31, hanish jadala [email protected] wrote:

hi all help me out guys

thanks in advance

On Tue, Jun 12, 2012 at 3:07 PM, hanish jadala [email protected]
wrote:

no with our changing the relationship can i update values.

We did - you refused to do it :-/

Let’s just restate your position: You want to have a habtm join, with
extra information in the join table. This type of join typically does
not have a model, and thus no way of updating those extra fields
(although a “feature” of Rails does/did extend columns in the join
table to both sides of the association).
You don’t want to add a new model and join through it (the way it
would be done normally).
So you see the circular problem you have…

Let’s take one step back; rather than demanding that people “help you
out”, maybe you can explain why you don’t want to change your
association…