[Dbix-class] Update a related table

Matt S Trout dbix-class at trout.me.uk
Sun Jul 20 02:27:35 BST 2008


On Mon, Jul 14, 2008 at 05:13:58PM +0100, Dermot wrote:
> Hi,
> 
> I am sure this is a simple task but I don't appear to be getting it.
> 
> t1 has a column in which I store the id for the members of t2
> 
> I can do this:
> 
> my $data_from_t1 = $c->model('MyDB::MyData')->find({'sub_id' => $id});
> 
> and I can retrieve the other table object from $data_from_t1 by
> 
> $data_from_t2 = $data_from_t1->t1_column_ref
> 
> But what if, in the process of updating t1, I want to update a field
> in a related record in t2. I can't seem to find a way to do that.
> 
> I have tried
> 
> $data_from_t2->field_to_update = 1;
> $data_from_t2->update;
> $data_from_t1_update;

$data_from_t2->field(1);
$data_from_t2->update;

or

$data_from_td->update({ field => 1 });

just like on any DBIx::Class::Row object.
> 
> Can someone point me in the right direction?
> Thanx,
> Dp.
> 
> _______________________________________________
> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.rawmode.org

-- 
      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director                    http://www.shadowcat.co.uk/catalyst/
 Shadowcat Systems Ltd.  Want a managed development or deployment platform?
http://chainsawblues.vox.com/            http://www.shadowcat.co.uk/servers/



More information about the DBIx-Class mailing list