http://cpansearch.perl.org/~jrobinson/DBIx-Class-0.08009/lib/DBIx/Class/Ordered.pm#Unique_Constraints

might be applying to you, and if not, Ordered might help you.

- andreas

On 31. jan.. 2008, at 02.35, Jay Varner wrote:

In short, I'm new to Catalyst and a near intermediate Perl programmer.
I've converted (and vastly improved) my app from CGI::Application to
Catalyst within an amount of time that made me feel like I wasted
those months I spent prior to using Catalyst. However, the past few
days I have been struggling with this one function that I just can't
get.

Honestly, I feel the easiest way for me to explain is to say that this
headache began by me trying to translate this bit of PHP code to
Perl/Catalyst: 
http://www.gregphoto.net/index.php/2007/01/16/scriptaculous-sortables-with-ajax-callback/

I'm just stuck. I've tried many things. My current/pressing attempt to
implement this is in a newsletter app where there is a "has many"
relationship between a Newsletter table and a table for Articles. The
join table has 3 columns – newsletter_id, article_id and ordering. So
I want to use that PHP and Ajax to allow a user to set the order that
articles will appear in a given newsletter. However, some articles
might appear in multiple newsletters. I might be going about this all
wrong and I would love to hear any suggestion of a better way.

For what it is worth, here is my current effort. I don't know if this
is the closest I've gotten, but it's where I'm at right now. This is
not actually my attempt at the the above, it's really just a scaled
back attempt to just figure out the DBIx for it begin sent by a basic
HTML form and not any Ajax shenanigans.

sub reorder : Local {
   my ($self, $c ) = @_;

# This just gets the the value for the later redirect to stay on the same page
        my $link = $c->request->params->{link};

# This is from a hidden value in a loop in the template [% article.id %]
        my @articles = $c->request->params->{article_id};

# Value for the newsletter we're working on. Again, this is from a hidden value
        my $newsletter_id = $c->request->params->{newsletter_id};

# This is obviously where I start trying shit to see if I can get it to work # The basic goal is to drop in the new value for ordering for each unique
        # article_id and newsletter_id in turn
        foreach my $article ( @articles ) {
my $newsletter = $c->model('SASSDB::ArticleNewsletter')- >search(
                                           {
                                           article_id => $article,
newsletter_id => $newsletter_id
                                           }
                                           );
                        my @orderings = $c->request->params->{ordering};
                                foreach my $ordering ( @orderings ) {
                                        $newsletter->update(
                                                {
                                                ordering => $ordering
                                                }
                                        );


                                }
                }

$c->response->redirect($c->uri_for("/admin/newsletters/ picked_articles/$link"));

}

This reasonably gives me the following:
DBIx::Class::ResultSet::update(): DBI Exception: DBD::mysql::st
bind_param failed: Illegal parameter number [for Statement "UPDATE
articles_newsletters SET ordering = 1 WHERE ( ( ( article_id = ? ) OR
( article_id = ? ) ) AND newsletter_id = ? )" with ParamValues:
1='12', 0='2', 2='18'] at ../lib/SASS/Controller/Admin/Newsletters.pm
line 200

Line 200 is  "$newsletter->update("

The body_parameters are:
body_parameters  => {
                       _submit => "Update",
                       _submitted_edit_menu => 1,
                       "_submitted_form_create" => 1,
                       article_id => [12, 18],
                       id => 1,
                       "link" => "Test",
                       newsletter_id => 1,
                       ordering => [1, 2],
                     },

Let me know if you want to see anything else.

Humbly placing myself on the mercy of the community,
Jay

_______________________________________________
List: [email protected]
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/


_______________________________________________
List: [email protected]
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/

Reply via email to