[CDBI] uniqueness of objects in memory??

Phil Mitchell phil at 2people.org
Mon Oct 24 18:42:08 BST 2005


On 10/24/05, Perrin Harkins <perrin at elem.com> wrote:
> On Sun, 2005-10-23 at 20:32 -0700, Phil Mitchell wrote:
> > 1. User has_a Prefs object; User->Prefs->home_page equals X
> > 2. Prefs gets updated with new data; Prefs->home_page equals Y
> > 3. But User->Prefs->home_page still equals X.
>
> Here are some possible reasons:
> 1. You are using an older Class::DBI that doesn't support this feature
> but looking at docs for a later version.

==I'm on 3.0.1

> 2. Your Perl doesn't support weak references.  I think the docs explain
> how to check this.

==It does ... perl -e 'use Scalar::Util qw(weaken)'

> 3. Your primary key for this class is defined incorrectly, so these
> objects do not appear the same to Class::DBI.

Not sure, but my usage is pretty simple:
__PACKAGE__->columns(Primary => qw/id /);

> 4. Something in the particular sequence of actions you're doing has
> uncovered a bug.  In that case, simmering it down to a small test case,
> would make it easier for people to help you with it.

I am surprised to find that I can rip out all the relationships
(except has_a(Prefs) of course) and triggers and still get this
result. Here's the boiled-down CDBI portions of my three classes:
User, Prefs, and Page -- User and Prefs are both subclasses of Page.

-------------------------------------------------------------
package Reef::M::DBI::Page;
use base 'Reef::M::DBI';

__PACKAGE__->table('page');
__PACKAGE__->columns(Primary => qw/id /);
__PACKAGE__->columns(Essential => qw/page_type
                                     created
                                     edit_date
                                     edit_by
                                     user_owner
                                     club_owner
                                     permissions
                                     locked_since
                                     locked_by
                                     title
                                     body
                                     home_page
                                     username
                                     password
                                     prefs
                                     shelf
                                    /);

----------------------------------------------------------
package Reef::M::DBI::Page::User;
use base 'Reef::M::DBI::Page';

__PACKAGE__->has_a(prefs => 'Reef::M::DBI::Page::Prefs');

-----------------------------------------------------------
package Reef::M::DBI::Page::Prefs;
use base 'Reef::M::DBI::Page';

-----------------------------------------------------------

Thanks for your help!

>
> - Perrin
>
>


--
==========================
2People Blog: http://2-people.blogspot.com/
2People site: http://www.2people.org




More information about the ClassDBI mailing list