-
-
14 Feb 2015 10:26:37 UTC
- Distribution: Catalyst-Plugin-AutoCRUD
- Source (raw)
- Browse (raw)
- Changes
- How to Contribute
- Issues (1)
- Testers (817 / 3 / 0)
- Kwalitee
Bus factor: 1- % Coverage
- License: perl_5
- Activity
24 month- Tools
- Download (93.13KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
- Dependencies
- Catalyst::Action::RenderView
- Catalyst::Controller
- Catalyst::Model
- Catalyst::Model::DBIC::Schema
- Catalyst::Plugin::ConfigLoader
- Catalyst::Plugin::Unicode::Encoding
- Catalyst::Runtime
- Catalyst::Utils
- Catalyst::View::JSON
- Catalyst::View::TT
- DBD::SQLite
- DBIx::Class
- DBIx::Class::Schema::Loader
- Data::Dumper
- Data::Page
- Devel::InnerPackage
- Exporter
- File::Basename
- File::Slurp
- File::stat
- JSON
- Lingua::EN::Inflect::Number
- List::MoreUtils
- List::Util
- MRO::Compat
- SQL::Translator
- SQL::Translator::Schema
- SQL::Translator::Schema::Table
- Scalar::Util
- base
- overload
- strict
- warnings
- and possibly others
- Reverse dependencies
- CPAN Testers List
- Dependency graph
- NAME
- General Advice
- Foreign keys should be configured with is_foreign_key
- Make sure belongs_to follows add_columns
- Optional belongs_to relations must have a join_type
- Columns with auto-increment data types
NAME
Catalyst::Plugin::AutoCRUD::Manual::DBICTips - Tips for DBIx::Class Users
General Advice
If you created your
DBIx::Class
Schema some time ago, perhaps using an older version ofDBIx::Class::Schema::Loader
, then it might well be lacking some configuration which is required to get the best results from this plugin.Common omissions in column configurations include
is_foreign_key
,join_type
,is_nullable
, andis_auto_increment
. Of course it's also good practice to have yourDBIx::Class
Schema closely reflect the database schema anyway.To automatically bring things up to date, download the latest version of DBIx::Class::Schema::Loader from CPAN, and use the output from that.
Foreign keys should be configured with
is_foreign_key
Any column in your result classes which contains the primary key of another table should have the
is_foreign_key => 1
option added to its configuration.If using
DBIx::Class::Schema::Loader
to generate your Schema, use at least version 0.05 or the most recent release from CPAN to have this automatically configured for you.Make sure
belongs_to
followsadd_columns
Whenver you use
belongs_to()
in a result class, it must come after any calls toadd_column()
which affect the foreign key. A situation where this may not be the case is if you add additional column options in a second call toadd_column()
, after theDO NOT MODIFY THIS OR ANYTHING ABOVE
line.If you do not follow this guideline, then you won't see any related data in the views generated by this plugin. Furthermore, you'll be losing much of the advantage of
DBIx::Class
.A better solution is to re-generate your result class using a recent version of
DBIx::Class::Schema::Loader
from the CPAN (which may be 0.05 or later).Optional
belongs_to
relations must have ajoin_type
If you have any
belongs_to
type relations where the column containing the foreign key can be NULL, it's strongly recommended that you add ajoin_type
parameter to the end of the relevant options toadd_columns()
, like so:# in a Book class, the book optionally has an Owner __PACKAGE__->belongs_to( 'my_owner', # accessor name 'My::DBIC::Schema::Owner', # related class 'owner_id', # our FK column (or join condition) { join_type => 'LEFT OUTER' } # attributes );
If you don't do this, some database records will be missing! The technical reason for this, if you are interested, is that
DBIx::Class
defaults to an INNER join for thebelongs_to()
relation, but if the column can be null (that is,is_nullable
) then you most likely want a LEFT OUTER join.If using
DBIx::Class::Schema::Loader
to generate your Schema, use at least version 0.05 or the most recent release from CPAN to have this automatically configured for you.Columns with auto-increment data types
For those columns where your database uses an auto-incremented value, add the
is_auto_increment => 1
parameter to the options list inadd_columns()
. This will let the plugin know you don't need to supply a value for new or updated records. The interface will look much better as a result.If using
DBIx::Class::Schema::Loader
to generate your Schema, use at least version 0.05 or the most recent release from CPAN to have this automatically configured for you.Module Install Instructions
To install Catalyst::Plugin::AutoCRUD, copy and paste the appropriate command in to your terminal.
cpanm Catalyst::Plugin::AutoCRUD
perl -MCPAN -e shell install Catalyst::Plugin::AutoCRUD
For more information on module installation, please visit the detailed CPAN module installation guide.