You can subscribe to this list here.
| 2002 |
Jan
|
Feb
|
Mar
|
Apr
(9) |
May
(6) |
Jun
(5) |
Jul
(3) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|---|
|
From: why t. l. s. <ja...@wh...> - 2002-07-02 16:01:59
|
Heya Nigel--
Does that LEFT JOIN query work for you or are you looking for a RIGHT JOIN?
Example:
mysql> create table test1 ( id int4, name char(20) );
mysql> create table test2 ( id int4, name char(20) );
mysql> insert into test1 values (2, 'Hello' );
mysql> insert into test1 values (3, 'Goodbye');
mysql> insert into test1 values (4, 'Forever');
mysql> insert into test2 values (4, 'Forever');
-- LEFT JOIN test2 -> test1
mysql> select * from test2 left join test1 on test1.id = test2.id;
+------+---------+------+---------+
| id | name | id | name |
+------+---------+------+---------+
| 4 | Forever | 4 | Forever |
+------+---------+------+---------+
1 row in set (0.00 sec)
-- LEFT JOIN test1 -> test2
mysql> select * from test1 left join test2 on test1.id = test2.id;
+------+---------+------+---------+
| id | name | id | name |
+------+---------+------+---------+
| 2 | Hello | NULL | NULL |
| 3 | Goodbye | NULL | NULL |
| 4 | Forever | 4 | Forever |
+------+---------+------+---------+
3 rows in set (0.00 sec)
-- RIGHT JOIN test2 -> test1
mysql> select * from test2 right join test1 on test1.id = test2.id;
+------+---------+------+---------+
| id | name | id | name |
+------+---------+------+---------+
| NULL | NULL | 2 | Hello |
| NULL | NULL | 3 | Goodbye |
| 4 | Forever | 4 | Forever |
+------+---------+------+---------+
3 rows in set (0.00 sec)
So the right join returns data, even when test2 has no content. Is that what you're looking for?
The trouble with mapping zero-to-many relationships in Psychoo is that every row of data in Psychoo represents an object -- a PHP instance. So data loaded from the database is accessed like this:
$boxes = $psychoo->load_all( array( 'box', 'content' ) );
foreach( $boxes as $box )
{
foreach( $box->content as $c )
{
// Handle the 'content' object
}
}
When Psychoo sees null rows, it creates no objects, as there are no means for creating objects from NULL data at the moment. It can't assign properties to a $box which is null. Of course, I want to see Psychoo accomodate any kind of data structure. At the moment, we just need to find a suitable nomenclature for representing null objects.
The other problem here is that the load_all defaults to a LEFT JOIN. Starting with the head table in your array, it will add LEFT JOINs to the query, as it scans your object list. The only exception is when your head table contains a foreign key to the primary key of a table deeper in the list. Often these are INNER JOINed.
So I imagine that we will keep load_all as it is, but add RIGHT JOINs to the new load queries. I'll have it ready by 1.1. In the meantime, I'll encourage people to use straight SQL. I wish Psychoo was all things to all people, but it's really a framework for eliminating the work that is the most common and most mundane. I know... I know... ALL SQL is COMMON and MUNDANE. ;)
_why
On Tue, 2 Jul 2002 14:28:23 +0100
"Nigel Armstrong" <Nig...@te...> wrote:
> Hi,
>
> Is there any way in the current release of javuh to generate a query like
> 'SELECT * FROM box LEFT JOIN content ON box.id = content.box_id'? The query
> generated by default by $psychoo->load_all(array('box', 'content')) returns no
> data when a box has no content, which is not what is wanted when you are
> modelling a zero to many relationship.
>
> Currently I am executing separate queries and merging the results; I could also
> hand code the SQL but that would somewhat defeat the purpose of using Javuh.
>
> Nigel
|
|
From: why t. l. s. <wh...@ry...> - 2002-05-11 23:42:57
|
> I couldn't figure out why you use that eval statement there. Just: $m
> = new $mixed_name(); has worked fine for me before. (Possibly it
> didn't work because you didn't include the parentheses?)
I guess with or without parens work. I'm going to make that change in
Javuh.inc. The fewer evals the better.
> Also, you could try combining it with my technique for more "natural"
> mixins... That is, something like:
>
> class Bartender {
> function mixin( $based_on ) {
> $mixed_name = "mixed_class_" . get_class($this) . "_" . implode(
> "_",
> $based_on );
> if ( !class_exists( $mixed_name ) )
> create_mixed_class( $mixed_name, $based_on );
> // Possibly, include some method for serializing data that needs to
> be
> available to new object.
> // ex: $this = new $mixed_name(get_object_vars($this));
> $this = new $mixed_name();
> }
> }
It kinda scares the willies out of me that PHP can do this kind of stuff
(replacing $this inside of a method), but it's a neat hack to get an
instance to change classes. In fact, this helps me complete the entire
goal of the mixin article. Here's the new mixin() function now in
Javuh.inc. Works great.
/**
* Mixes an instance into a new class [Thanks, WorldMaker!]
* @param $o An object, the instance
* @param $based_on Classes to mix together
* @return Object
*/
function mixin( &$this, $based_on )
{
if ( !is_object( $this ) )
{
site_halt( 'Javuh,Mixin', 'Function <b>mixin()</b> should be
passed an object or <B>$this</B>.' ); }
array_unshift( $based_on, get_class( $this ) );
$mixed_name = "mixed_class_" . implode( "_and_", $based_on );
if ( !class_exists( $mixed_name ) )
create_mixed_class( $mixed_name, $based_on );
$vars = get_object_vars( $this );
$this = new $mixed_name;
foreach( $vars as $k => $v )
{
$this->$k = $v;
}
}
> overload() is definitely something, and it will be nice to see it going
> mainstream. I know there have been plenty of times when I could have
> used it. Personally, I think all classes should be overload()d in such
> that if a variable/function is not defined it should cause a "404" and
> seek out such functions, or at least, if you define such functions in a
> class, it should automatically be overload()d.
I played with the overload() function and found it sort of cool. I wish
it gave me a context for how the variable is being used. I solved my
initial problem by simply having functions named the same as my member
variables. I'll get into it sometime soon...
So all the mixin stuff we could hope for is now implemented and
functioning like a champ without any additional compile flags to PHP.
Javuh 1.0.2 is on its way, people!
|
|
From: why t. l. s. <ja...@wh...> - 2002-04-22 16:54:39
|
Jeff:
I believe this is a case-sensitivity issue. I am checking some
changes into CVS that will work with the CamelCase object names, but in
the meantime you may want to keep the object names as 'jobopening' and
'company'. I've always done my .oo without uppercase, so the results
are sort of unpredictable. The next release will be case-insensitive,
so whether you call it 'JobOpening' or 'jobopening' it will be the same.
I believe this is consistent with most databases.
If that doesn't work, please reply and I'll see if I can make
another good guess.
Jeff Lewis wrote:
>Ok, I made it past the first set of errors, but I am
>now getting the following:
>
>Warning: Invalid argument supplied for foreach() in
>c:\apache\htdocs\javuh-1.0.1\Model\Psychoo\Data\SQL.inc
>on line 550
>
>Warning: Invalid argument supplied for foreach() in
>c:\apache\htdocs\javuh-1.0.1\Model\Psychoo\Data\SQL.inc
>on line 203
>
>Here are the pertainent parts of the .oo file:
>[JobOpening:
> [m_id:
> [type: auto_key /]
> /]
> [m_companyID:
> [type: link /]
> [name: Company /]
> [link: Company.m_id /]
> [select: <Company.m_id> - <Company.m_name> /]
> [required: true /]
> /]
>/]
>[Company:
> [m_id:
> [type: auto_key /]
> /]
> [m_name:
> [type: varchar /]
> [name: Company Name /]
> [size: 50 /]
> [required: true /]
> [unique: none /]
> /]
>/]
>
>And here is the php code:
> require_once("Javuh.inc");
>
> class MyDB extends SQL_MySQL
> {
> var $Database = "test_javuh";
> var $User = "jdl";
> var $Password = "shakira";
> }
>
> class MyPsychoo extends Model_Psychoo
> {
> var $cache = "codestore";
> }
>
> $p = new MyPsychoo( "Site.oo" );
> $p->set_storage( new MyDB );
>
> $p->make_form( "a_form", array( "JobOpening" ) );
> $p->set_form_explain( "a_form", TRUE );
> echo $p->write_html_form( "a_form" );
>
>Any ideas on what I am doing wrong?
>
>Thanks,
>
>__________________________________________________
>Do You Yahoo!?
>Yahoo! Games - play chess, backgammon, pool and more
>http://games.yahoo.com/
>
>_______________________________________________
>Javuh-develop mailing list
>Jav...@li...
>https://lists.sourceforge.net/lists/listinfo/javuh-develop
>
>
|