FAQ
Using the helpers, I created a Model Bar

tmp_server lists all of its classes and instances like such...
TMP::Model::Bar | instance |
TMP::Model::Bar::Bar | class |
TMP::Model::Bar::HeHe | class |
TMP::Model::Bar::HaHa | class |
This continues for every table in the schema. Each has a prefix of Bar.

if I create another model using the helper, called Foo, with the same
schema object, it repeats. Every table in the schema, prefixed with
Foo.

I can only load the resultsets by calling $c->model("Bar::Bar")
I can only load the result set by calling $c->model("Foo::Foo")

This looks ugly and will get even uglier I am sure as the app grows.

Haven't been able to avoid this behavior. Is there a good reason for
this or am I making a mistake?

Thank you in advance. Below is some sample code

---

Package TMP::Schema;

use base qw/DBIx::Class::Schema DBIx::Class::AccessorGroup/;

__PACKAGE__->mk_group_accessors(simple => 'context');
__PACKAGE__->load_classes( qw// );

1;

---

Package TMP::Model::Bar;

use strict;
use base 'Catalyst::Model::DBIC::Schema';

__PACKAGE__->config(
schema_class => 'TMP::Schema'

.....

Search Discussions

  • Matt S Trout at Jun 7, 2007 at 5:58 pm

    On Thu, Jun 07, 2007 at 11:35:00AM -0500, Guy Debord wrote:
    Using the helpers, I created a Model Bar

    tmp_server lists all of its classes and instances like such...
    TMP::Model::Bar | instance |
    TMP::Model::Bar::Bar | class |
    TMP::Model::Bar::HeHe | class |
    TMP::Model::Bar::HaHa | class |
    This continues for every table in the schema. Each has a prefix of Bar.

    if I create another model using the helper, called Foo, with the same
    schema object, it repeats. Every table in the schema, prefixed with
    Foo.
    You only need one DBIC::Schema model per DBIx::Class::Schema class - try
    calling it Model::DB or something and then just use ->model('DB::Foo'),
    ->model('DB::Bar') etc.

    --
    Matt S Trout Need help with your Catalyst or DBIx::Class project?
    Technical Director Want a managed development or deployment platform?
    Shadowcat Systems Ltd. Contact mst (at) shadowcatsystems.co.uk for a quote
    http://chainsawblues.vox.com/ http://www.shadowcatsystems.co.uk/
  • Guy Debord at Jun 7, 2007 at 9:39 pm
    Matt et al,

    All of my models -- such as TMP::Model::Foo -- created by the helper
    -- use DBIC::Schema as a base class and are configured to use
    TMP::Schema as their schema_class.

    Each model that I created through the helper ends up creating classes
    in the namespace, one for each table in my database prefixed by that
    model's name.

    So for example, here are some classes

    TMP::Model::Foo::Foo
    TMP::Model::Bar::Bar
    TMP::Model::Foo::Table1 .. Table100
    Same for Bar, and everything else.

    TMP::Model::Foo, Bar etc exist individually as instances.

    IN terms of accessing the recordsets, $c->model("Foo::Foo") and
    $c->model("Bar::Foo") return the same object.

    $c->model("Foo") doesn't return anything.

    To create the models, I first used:

    tmp_create.pl model Bar DBIC::Schema TMP::Schema create=static connect_info

    and then subsequent models Foo, etc, I created leaving off create=static.

    any pointers would be appreciarted.





    On 6/7/07, Matt S Trout wrote:
    On Thu, Jun 07, 2007 at 11:35:00AM -0500, Guy Debord wrote:
    Using the helpers, I created a Model Bar

    tmp_server lists all of its classes and instances like such...
    TMP::Model::Bar | instance |
    TMP::Model::Bar::Bar | class |
    TMP::Model::Bar::HeHe | class |
    TMP::Model::Bar::HaHa | class |
    This continues for every table in the schema. Each has a prefix of Bar.

    if I create another model using the helper, called Foo, with the same
    schema object, it repeats. Every table in the schema, prefixed with
    Foo.
    You only need one DBIC::Schema model per DBIx::Class::Schema class - try
    calling it Model::DB or something and then just use ->model('DB::Foo'),
    ->model('DB::Bar') etc.

    --
    Matt S Trout Need help with your Catalyst or DBIx::Class project?
    Technical Director Want a managed development or deployment platform?
    Shadowcat Systems Ltd. Contact mst (at) shadowcatsystems.co.uk for a quote
    http://chainsawblues.vox.com/ http://www.shadowcatsystems.co.uk/

    _______________________________________________
    List: Catalyst@lists.rawmode.org
    Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
    Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
    Dev site: http://dev.catalyst.perl.org/
  • Matt S Trout at Jun 7, 2007 at 10:13 pm

    On Thu, Jun 07, 2007 at 03:40:00PM -0500, Guy Debord wrote:
    Matt et al,

    All of my models -- such as TMP::Model::Foo -- created by the helper
    -- use DBIC::Schema as a base class and are configured to use
    TMP::Schema as their schema_class.
    Yes. You only need *one* model per DBIC::Schema!
    tmp_create.pl model Bar DBIC::Schema TMP::Schema create=static connect_info
    tmp_create.pl model DB DBIC::Schema TMP::Schema

    $c->model('DB::Foo')
    $c->model('DB::Bar')

    etc.

    --
    Matt S Trout Need help with your Catalyst or DBIx::Class project?
    Technical Director Want a managed development or deployment platform?
    Shadowcat Systems Ltd. Contact mst (at) shadowcatsystems.co.uk for a quote
    http://chainsawblues.vox.com/ http://www.shadowcatsystems.co.uk/
  • Guy Debord at Jun 8, 2007 at 6:11 pm
    So is this not a good option if I want specific logic in Model::Foo but not
    Model::Bar ( I can't even create these without breaking )
    This seems to run contrary to my reading of the documentation and tutorials,
    etc.


    On 6/7/07, Matt S Trout wrote:
    On Thu, Jun 07, 2007 at 03:40:00PM -0500, Guy Debord wrote:
    Matt et al,

    All of my models -- such as TMP::Model::Foo -- created by the helper
    -- use DBIC::Schema as a base class and are configured to use
    TMP::Schema as their schema_class.
    Yes. You only need *one* model per DBIC::Schema!
    tmp_create.pl model Bar DBIC::Schema TMP::Schema create=static
    connect_info

    tmp_create.pl model DB DBIC::Schema TMP::Schema

    $c->model('DB::Foo')
    $c->model('DB::Bar')

    etc.

    --
    Matt S Trout Need help with your Catalyst or DBIx::Class
    project?
    Technical Director Want a managed development or deployment
    platform?
    Shadowcat Systems Ltd. Contact mst (at) shadowcatsystems.co.uk for a
    quote
    http://chainsawblues.vox.com/ http://www.shadowcatsystems.co
    .uk/

    _______________________________________________
    List: Catalyst@lists.rawmode.org
    Listinfo: http://lists.rawmode.org /mailman/listinfo/catalyst
    Searchable archive: http://www.mail-archive.com/catalyst@
    lists.rawmode.org/
    Dev site: http://dev.catalyst.perl.org/
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20070608/964c00e5/attachment-0001.htm
  • Matt S Trout at Jun 8, 2007 at 6:50 pm

    On Fri, Jun 08, 2007 at 12:11:10PM -0500, Guy Debord wrote:
    So is this not a good option if I want specific logic in Model::Foo but not
    Model::Bar ( I can't even create these without breaking )
    This seems to run contrary to my reading of the documentation and tutorials,
    The tutorial uses DBIC::Schema exactly as I've described.

    If you want additional logic, why not just add it to your My::Schema::Foo
    etc. classes so it's available outside of Catalyst as well?

    --
    Matt S Trout Need help with your Catalyst or DBIx::Class project?
    Technical Director Want a managed development or deployment platform?
    Shadowcat Systems Ltd. Contact mst (at) shadowcatsystems.co.uk for a quote
    http://chainsawblues.vox.com/ http://www.shadowcatsystems.co.uk/
  • Jay Shirley at Jun 8, 2007 at 7:52 pm

    On 6/8/07, Guy Debord wrote:
    So is this not a good option if I want specific logic in Model::Foo but
    not Model::Bar ( I can't even create these without breaking )
    This seems to run contrary to my reading of the documentation and
    tutorials, etc.
    Hi Guy,

    I think that a diagram of how things are encapsulated would probably be of
    assistance. Sorry if I'm covering stuff you already know, just want to make
    sure everything is thoroughly laid out.

    First, it's important to know how things work outside of Catalyst. The DBIC
    classes you have can be used just like $schema->resultset('TableName'),
    where $schema is (as I can see) a "TMP::Schema" object.

    The DBIC::Schema helpers basically create a short-hand for you to access
    "TableName", but they make you use some prefix. This is really useful if
    you have a model in your app called "User" but you also have a schema class
    (a database table) named "User"

    As an example, something like this:
    $c->model("User"); # Just some other model class
    $c->model("DB::User"); # A DBIC class resultset, equivalent to doing
    $schema->resultset('User')

    So, just think that when you are doing "$c->model("DB::SomeTable")" you're
    doing the equivalent of $schema->resultset("SomeTable"); And, as such,
    $c->model("DB") would be somewhat analogous to returning the $schema object
    -- except it doesn't, because that gets shoved off behind the scenes, and
    Model::DBIC::Schema creates a map between the ->resultset("TableName") and
    model("DB::TableName") automatically, so you shouldn't need the $schema
    object to get at the result sets.

    The prefix there ("DB::") is configurable via the helper scripts, but is
    very important (both for the reason I listed above w/ having other model
    classes) and the way that Catalyst::Model::DBIC imports your schema classes
    into your Catalyst application.

    The syntax that Matt posted:
    script/tmp_create.pl model DB DBIC::Schema TMP::Schema

    Breaks down like this:
    You're creating (tmp_create.pl) a model, with a prefix of "DB" that inherits
    from "DBIC::Schema" and will use Helper::DBIC::Schema to generate the code.

    The arguments beyond there ("TMP::Schema") are instructive to
    Helper::DBIC::Schema to know what to map against.

    Helper::DBIC::Schema then creates a map of the prefix ("DB") to
    "TMP::Schema".

    You're on the right track though, and what you said in the original post
    about it getting "ugly" as the app grows I suppose is just a matter of
    perspective. You can always run without debugging enabled so you don't see
    how things get dumped out. But, it's all just information for you to look
    at. Even without the ("DB::") prefix (or "Foo::" as you have in your
    example) you'd still have to load each and every schema class into Catalyst
    so that ->model(...) knows what to work with.

    Hope this helps clear things up,
    -Jay

    --
    J. Shirley :: jshirley@gmail.com :: Killing two stones with one bird...
    http://www.toeat.com
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20070608/f00dd8b3/attachment.htm

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedJun 7, '07 at 5:34p
activeJun 8, '07 at 7:52p
posts7
users3
websitecatalystframework.org
irc#catalyst

People

Translate

site design / logo © 2022 Grokbase