<div dir="ltr"><div><div><div><div><div><div><div><div><div>Having in mind you are new to perl, do not continue development untill you learn about Data::Dumper and Data::Printer. With these tools you can Dump the contents of variables/objects and see which methods and attributes are avaliable, and you can see the type of those variables/objects. <br>
<br></div>You can do so by trying: <br><br></div>$ perl -e  &#39;use URI; my $x=URI-&gt;new(&quot;<a href="http://www.bla.com/bla">http://www.bla.com/bla</a>&quot;) ; use DDP; warn p $x; &#39;\<br><br></div>So when you do that with $user, you will find out $user is actually related to DBIx::Class object. And, that method create_related is actually related to DBIx::Class. <br>
<br></div>When you do: $c-&gt;model(&#39;DB::User&#39;)-&gt;new_result({});     You are actually using the DB::User model which is a DBIx::Class table class.<br><br></div>DBIx::Class is the orm the tutorial uses. And also probably the most complete orm from all the existing programing languages. <br>
<br></div>If you want to learn more about DBIx::Class, you must read the documentation: <a href="http://search.cpan.org/dist/DBIx-Class/lib/DBIx/Class/ResultSet.pm#new_result">http://search.cpan.org/dist/DBIx-Class/lib/DBIx/Class/ResultSet.pm#new_result</a><br>
<br></div>I would suggest you halt your development there, and start another &quot;quicky&quot; one that will only use DBIx::Class orm. So you can create 1 &#39;test table&#39; in your sql test database with a couple rows. Then, you can make a quick script (a simple <a href="http://perl.pl">perl.pl</a> file) and try to create, update, delete and select rows from that table using the DBIx::Class orm. Also have in mind that people often call DBIx::Class as dbic. That simple perl script would look something like this: <br>
<br></div>0. create a simple database with a simple table with a couple of columns. (you can do that in your database)<br></div>1. create the orm schema using <span class=""><em>DBIx</em>::<em>Class</em>::<em>Schema</em>::<em>Loader </em>like this:<br>
</span><br><pre class="">    dbicdump -o dump_directory=./lib \
    -o debug=1 \
    DB::Some::Database::Namespace \
    &#39;dbi:Pg:dbname=your_database_name&#39; \
     myuser \
    mypassword</pre><span class="">2. create a <a href="http://script.pl">script.pl</a> that will use the generated schema:<em><br></em></span><br><pre class="">    use lib ( &quot;./lib&quot; );
    use DBSchema;  medico
    my $schema = DBSchema-&gt;connect(&#39;dbi:Pg:dbname=your_database_name&#39;, &#39;hernan&#39;, &#39;lopes&#39;);
    my $plant  = $schema-&gt;resultset(&#39;Plant&#39;)-&gt;find({ id =&gt; 1}); #search in table Plant where id = 1
    print $plant-&gt;color; #green<br><br></pre><pre class="">check the dsn correct for your database... dbi::Pg:dbname is for postgres. Lookup the one you must use.<br><br></pre><pre class="">also, when you execute the <a href="http://script.pl">script.pl</a> you can do so with the DBIC_TRACE=1 option, ie: $ export DBIC_TRACE=1 &amp;&amp; perl <a href="http://script.pl">script.pl</a> <br>
</pre><pre class="">That way you will see debug output.<br><br>One handy dbic row method is: <a href="http://search.cpan.org/~ribasushi/DBIx-Class-0.08250/lib/DBIx/Class/Row.pm#update_or_insert">http://search.cpan.org/~ribasushi/DBIx-Class-0.08250/lib/DBIx/Class/Row.pm#update_or_insert</a><br>
<br></pre><pre class="">try using that one. When you are able to insert, update and search and find, try creating relationships among tables and re-run the dbicdump command so your orm mappings get updated. Also, remember -&gt;search returns multiple items and -&gt;find is for 1 item.<br>
<br></pre><pre class="">then you will be able to continue on that example you are working on, all by yourself.<br></pre><pre class=""><br><br></pre><pre class="">And, welcome to perl and catalyst, I hope you are being able to do what you need. Its powerful tools once you master them.<br>
</pre><pre class=""><br></pre></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Jun 5, 2014 at 8:20 PM, Bob Miller <span dir="ltr">&lt;<a href="mailto:bob@computerisms.ca" target="_blank">bob@computerisms.ca</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello<br>
<br>
I am new to Perl and Catalyst, I hope I my terminology correct.  much<br>
gratitude to the authors of the fine Catalyst documentation, the<br>
tutorials are excellent tools of understanding...<br>
<br>
I have been through the tutorial and am currently modelling after the<br>
authentication and authorization article on the advent calendar found<br>
here:<br>
<br>
<a href="http://www.catalystframework.org/calendar/2011/15" target="_blank">http://www.catalystframework.org/calendar/2011/15</a><br>
<br>
The goal:<br>
<br>
I want users of roleB to create new users that are automatically set to<br>
roleA.  So I created an authentication chain, and have created a related<br>
set of templates and forms to play with.  The goal is to remove the Role<br>
selection option and have the userroles join table updated automatically<br>
at user creation time.<br>
<br>
The efforts:<br>
<br>
I started in Form/EditUser.pm has_field arguments by setting a &quot;default<br>
=&gt; 1&quot; argument and omitting the field from displaying in the template,<br>
but it did not update the join field.<br>
<br>
I found in HTML::FormHandler::Manual::Defaults an explanation that if<br>
the item object contains an accessor, the default won&#39;t be used.  since<br>
in following the example I am using an accessor, it seems I will not<br>
succeed using the form to set the value.<br>
<br>
I looked at the useradd sub in the example again, I saw fields being<br>
automatically set like so:<br>
<br>
my $user = $c-&gt;model(&#39;DB::User&#39;)-&gt;new_result({});<br>
$user-&gt;password($temp_password);<br>
<br>
So I figured I should be able to use the accessor to  do the same in the<br>
join table, maybe like:<br>
<br>
$user-&gt;userroles({&#39;roleid&#39; =&gt; &#39;1&#39;});<br>
<br>
This, nor any variation on syntax I tried, does not update the join<br>
table when the user is created.<br>
<br>
I went back through the basicCRUD tutorial, and found the example where<br>
the book_author table is updated, and it uses an argument called<br>
create_related (or add_to_$rel), so I tried<br>
<br>
$user-&gt;create_related(&#39;userroles&#39;, {roleid =&gt; &#39;1&#39;});<br>
<br>
It actually works quite well in that when the form is processed the user<br>
is created and the proper entries are made in the join table, but has<br>
the unfortunate side effect of creating an empty user every time I hit<br>
the form as well.<br>
<br>
In digging around, I found also a new_related function, which based on<br>
what I read should do exactly what create_related does, except only when<br>
the form is processed and not when I touch the form:<br>
<br>
$user-&gt;new_related(&#39;userroles&#39;, {roleid =&gt; &#39;1&#39;});<br>
<br>
But this also does not update the join table when the user is created.<br>
<br>
The question:<br>
<br>
have I discovered the right tool but used it incorrectly, or am I going<br>
about this the wrong way?  If the former, that is all I need to know, I<br>
will dance with what I have till the light comes on.  If the latter, can<br>
someone please point me at the page I need to read?<br>
<br>
Thank you for taking the time to read...<br>
<br>
<br>
--<br>
Computerisms<br>
Bob Miller<br>
<a href="tel:867-334-7117" value="+18673347117">867-334-7117</a> / <a href="tel:867-633-3760" value="+18676333760">867-633-3760</a><br>
<a href="http://computerisms.ca" target="_blank">http://computerisms.ca</a><br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
List: <a href="mailto:Catalyst@lists.scsys.co.uk">Catalyst@lists.scsys.co.uk</a><br>
Listinfo: <a href="http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst" target="_blank">http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst</a><br>
Searchable archive: <a href="http://www.mail-archive.com/catalyst@lists.scsys.co.uk/" target="_blank">http://www.mail-archive.com/catalyst@lists.scsys.co.uk/</a><br>
Dev site: <a href="http://dev.catalyst.perl.org/" target="_blank">http://dev.catalyst.perl.org/</a><br>
</blockquote></div><br></div>