[jifty-devel] column in Model references ModelCollection

Jesse Vincent jesse at bestpractical.com
Tue Mar 18 16:16:24 EDT 2008




On Tue, Mar 18, 2008 at 07:25:19PM +0100, Peter Mottram wrote:
> Hi All
> 
> I guess I'm being too stupid here but what I'm trying to achieve in my 
> model is:
> 
> 
> package MyApp::Model::Foo;
> use Jifty::DBI::Schema;
> use MyApp::Record schema {
> 
>      column one =>          type is 'text';
> 
>      column two =>          references MyApp::Model::BarCollection by 'required_by',          default is undef;
> };
> 
> 
 
> Weirdly jifty schema --setup doesn't bother creating column two in foos 
> and throws no errors or warnings to give me a clue.

For a one-to-many relationship like that, what you want is actually a
_virtual_ column. (Columns can only contain one value).

So referencing a collection as a column "just works"


my $foo = MyApp::Model::Foo->new();
$foo->load_by_cols(id => 12);


my $collection = $foo->two;
while (my $two = $collection->next) {

	# do something with $two
}







> 
> What I really need is to have one record in Foo to be able to reference a 
> collection of Foo records but whatever method I try gets nowhere fast.
> 
> Can anyone give me a clue as to what to try next? I have played with 
> referencing collections in a much simpler form and just can't get the damn 
> things to cooperate in any way. I'm even getting close to implementing 
> this using just Mason and DBI (faithful old friends). :-(
> 
> TIA
> PeteM
> _______________________________________________
> jifty-devel mailing list
> jifty-devel at lists.jifty.org
> http://lists.jifty.org/cgi-bin/mailman/listinfo/jifty-devel
> 

-- 


More information about the jifty-devel mailing list